I am trying to understand some socket code. One of the function calls is as follows:
Just wondering what the syntax for the last two arguments means and how it works.Code:msgsock = accept(sock, (struct sockaddr *)0, (int *)0);
Thanks in advance.
This is a discussion on Help with pointer syntax within the C Programming forums, part of the General Programming Boards category; I am trying to understand some socket code. One of the function calls is as follows: Code: msgsock = accept(sock, ...
I am trying to understand some socket code. One of the function calls is as follows:
Just wondering what the syntax for the last two arguments means and how it works.Code:msgsock = accept(sock, (struct sockaddr *)0, (int *)0);
Thanks in advance.
In this example, you are saying accept a connection on sock and you are not collecting any information about who that is (since the destination address for the last two arguments is 0). It might be a better practice to just use NULL here, if accept() will accept that.
The reason you might need to cast zero would be that accept() expects a pointer of some specific sort.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
both are NULL pointers cast to the proper type