Thread: Help with pointer syntax

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    Help with pointer syntax

    I am trying to understand some socket code. One of the function calls is as follows:

    Code:
    msgsock = accept(sock, (struct sockaddr *)0, (int *)0);
    Just wondering what the syntax for the last two arguments means and how it works.

    Thanks in advance.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    both are NULL pointers cast to the proper type

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM