Thread: integer null question

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    integer null question

    when i say
    Code:
    flag=(int)NULL;
    
    is it the same this as  saying
    
    flag=0;
    ??

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes (at least conceptually), like I said a long time ago (well, several days ago, at least) - along with about 6 other code-improvement suggestions that you ignored completely.

    Edit: http://cboard.cprogramming.com/showp...1&postcount=42

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    this function works fine. its an incarnation of a pointer version
    the null is a remainder from that version

    what problem could it do if i will change
    Code:
    flag=(int)NULL;
    to
    flag=0

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by me

    Code:
        if (input[0] != '(')
        {
            flag=(int)NULL;
        }
    (Repeats in several places)
    Surely this doesn't need to be using "(int)NULL", when what you REALLY want is flag=0? It's much clearer and simpler, and does what you want, doesn't it? NULL in C is used to indicate that a pointer is invalid - should not be used for integer variables....
    How is that different from what you are currently saying?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    ok i changed it
    it works fine

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by transgalactic2 View Post
    this function works fine. its an incarnation of a pointer version
    the null is a remainder from that version

    what problem could it do if i will change
    Code:
    flag=(int)NULL;
    to
    flag=0
    Well, although NULL is normally defined as 0. It *could* also be something else... You shouldn't use NULL for ints anyway. NULL is for pointers.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by QuantumPete View Post
    Well, although NULL is normally defined as 0. It *could* also be something else... You shouldn't use NULL for ints anyway. NULL is for pointers.

    QuantumPete
    Which is what I said 5 days back... - But apparently I didn't say it clearly enough [and I think Transgalactic wasn't quite listening, because it didn't actually fix the particular problem he/she was asking about].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 01:00 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. linked list problem
    By kzar in forum C Programming
    Replies: 8
    Last Post: 02-05-2005, 04:16 PM