C-language writing socket

Asked 2 years ago, Updated 2 years ago, 31 views

I'm looking at the object in the C language socket file, is this a function?Is it a structure?
I think it looks like a function, but I don't know the Int type variable in front of the parentheses.

Please tell me why it is in this position and what it is.
Thank you for your cooperation.

int
__socket(domain, type, protocol)
     int domain;
     int type;
     int protocol;
{
  __set_errno(ENOSYS);
  return-1;
}

c

2022-09-29 22:28

2 Answers

It is called K&R style in the C language function notation.

Syntax in The C Programming Language (1st edition), which was first published in 1978.
Then, when ANSIC is defined, the syntax is changed to the present form.The 1988 edition of The C Programming Language (end edition) supports ANSIC and the syntax for the question disappears.

So the socket program itself was made a long time ago.

I don't know the source of the source code posted in the question, but based on the function name, I assume that socket(2) will be built into the operating system.Some of the C compilers that come with the operating system are old, and you may have to choose the old format if you try to use them.

For example, the programming language Perl works in many operating systems.This means that it can be compiled with the C compiler available in many operating systems.For this reason, Perl has long adopted the K&R style.Perl has been requesting an ANSIC-style compiler since the 5.005 release in 1998 (although that was a long time ago…)


2022-09-29 22:28

int
__socket(domain, type, protocol)
     int domain;
     int type;
     int protocol;
{
  __set_errno(ENOSYS);
  return-1;
}

If you write in this style,

 int_socket(int domain, int type, int protocol)
{
  __set_errno(ENOSYS);
  return-1;
}

will be

The first int is the return value.


2022-09-29 22:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.