Thread: Null pointer naming

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The question is whether foo(void); could ever be considered to be a function declaration, as it appears Prelude is suggesting it could be. In order for it to be ambiguous when void means null, it would have to have a legitimate meaning now when void doesn't mean null. That would be why you might test it on your compiler.

    As it is, I'm not sure that it is valid syntax, now. Perhaps Prelude can explain the ambiguity she believes would arise.

  2. #17
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Daved
    The question is whether foo(void); could ever be considered to be a function declaration, as it appears Prelude is suggesting it could be. In order for it to be ambiguous when void means null, it would have to have a legitimate meaning now when void doesn't mean null. That would be why you might test it on your compiler.

    As it is, I'm not sure that it is valid syntax, now. Perhaps Prelude can explain the ambiguity she believes would arise.
    while I agree that it wouldn't necessarily cause compiler-level ambiguity, I think naming the null pointer void would cause immense confusion.

    Besides they are 2 semantically different concepts.
    void indicates lack of type.
    nullptr indicates that a pointer points to a non-existant object (which usually has a type!)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    void wouldn't mean null. Void would mean null pointer. That is at least the understanding I have of this dicussion at the light of the PDF file provided.

    In that context, foo(void) generates ambiguity. Isn't that so?

    If void meant null, then foo(void) would be an error if it was a declaration, but a perfectly valid syntax if it was a function call.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I think naming the null pointer void would cause immense confusion.
    The original question was whether there is a technical reason for not using void. I do not know if there is one or not (perhaps Prelude's example is that reason).

    I do agree that it would cause confusion, and I certainly would prefer nullptr over void. However, you must consider that adding a keyword is not something that is done lightly, and any potentially adequate solution that avoids adding a keyword should be considered.

    My guess is that those working on this proposal have considered void and opted against it, and asking this question at comp.lang.c++.moderated would likely provide the best answer and explanation as to why. I also highly doubt that I would have much of a disagreement with whatever that explanation is.
    Last edited by Daved; 06-20-2006 at 04:59 PM.

  5. #20
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Well there would be ambiguity if you did this:
    typeid(void);
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #21
    Registered User
    Join Date
    Jun 2006
    Posts
    2
    Well there would be ambiguity if you did this: typeid(void);
    "The null pointer cannot be used as the argument of a sizeof, typeid, or throw expression;" (from p. 2 of the pdf)

    The same would apply for your example. It would to ilegal as it is now.

    Code:
    int main() 
    {
      foo ( void );
    }
    If void meant null, then foo(void) would be an error if it was a declaration, but a perfectly valid syntax if it was a function call.
    Foo(void) cannot be a function declaration because
    a) C does not support nested funtions
    b) a function decleration would require a return value (possible void)

    I am very well aware of the ambiguous understanding of the keyword void this would introduce. But C can hardly be concidered a simple language as it is right now.

  7. #22
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >a) C does not support nested funtions
    C and C++ both support function declarations within a function body. You're thinking of a function definition.

    >But C can hardly be concidered a simple language as it is right now.
    That's not an excuse for heaping even more complexity onto the language definition.
    My best code is written with the delete key.

  8. #23
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    #define zen void

    The null pointer shall point at nothing, and nothingness is the essence of zen, zen itself is thus pointing at null, and so, the circle of of code is complete. Know this, and know, that void ptr is the zen of C and C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. addrinfo Structure Not Working
    By pobri19 in forum Networking/Device Communication
    Replies: 9
    Last Post: 10-22-2008, 10:07 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 09:57 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM