Re: Problem with NULL in g++

Discussion in 'C++' started by Gopi Subramanian, Jun 24, 2003.

  1. (tom_usenet) wrote in message news:<>...
    > On 23 Jun 2003 05:22:14 -0700, (Gopi
    > Subramanian) wrote:
    >
    > >I am porting a c++ source from suse linux to windows,and my code does
    > >a lot of binary file manipulation, during a debug session found that
    > >NULL values are different in VC ++ and g++, VC++ defines NULL as 0 and
    > >g++ defines it as a (void *) 0, is there any way to make sure that
    > >both of them matches ?

    >
    > The G++ definition is illegal in C++, where NULL must be an integral
    > constant expression equal to 0 (such as 0 or 0l) - I assume you have a
    > very old version of g++. Are you sure you aren't looking at the
    > definition it uses for C code?
    >
    > What problem is the difference in definition causing you anyway?
    >
    > Tom


    The Problem i am facing is once the data is read from binary file for
    the program negates 128 and then AND's it with the value read from
    binary file, when the value read is 128, 128 & ~128 yields 0. If i
    pipe the out put of intermediate values and look in vi, the character
    output in windows differs from the character output in linux. This is
    because g++ and vc++ are treating 0 in different way, if i #define
    NULL to 0 in only a particular file where this operation is carried
    out then, vi shows the same character for both windows and linux
    output.
    Gopi Subramanian, Jun 24, 2003
    #1
    1. Advertising

  2. "Gopi Subramanian" <> wrote...
    > (tom_usenet) wrote in message

    news:<>...
    > > On 23 Jun 2003 05:22:14 -0700, (Gopi
    > > Subramanian) wrote:
    > >
    > > >I am porting a c++ source from suse linux to windows,and my code does
    > > >a lot of binary file manipulation, during a debug session found that
    > > >NULL values are different in VC ++ and g++, VC++ defines NULL as 0 and
    > > >g++ defines it as a (void *) 0, is there any way to make sure that
    > > >both of them matches ?

    > >
    > > The G++ definition is illegal in C++, where NULL must be an integral
    > > constant expression equal to 0 (such as 0 or 0l) - I assume you have a
    > > very old version of g++. Are you sure you aren't looking at the
    > > definition it uses for C code?
    > >
    > > What problem is the difference in definition causing you anyway?
    > >
    > > Tom

    >
    > The Problem i am facing is once the data is read from binary file for
    > the program negates 128 and then AND's it with the value read from
    > binary file, when the value read is 128, 128 & ~128 yields 0. If i
    > pipe the out put of intermediate values and look in vi, the character
    > output in windows differs from the character output in linux. This is
    > because g++ and vc++ are treating 0 in different way, if i #define
    > NULL to 0 in only a particular file where this operation is carried
    > out then, vi shows the same character for both windows and linux
    > output.


    How are you reading the values? 'char' may not be able to support
    value 128. Are you sure they types on Windows and Linux are the
    same? And I don't think NULL has anything to do with that, sorry.

    In any case, why not post the code that doesn't work the same way
    on different platforms? I bet that if you missed something there,
    somebody will be able to point it out...

    Victor
    Victor Bazarov, Jun 24, 2003
    #2
    1. Advertising

  3. Gopi Subramanian

    Yamin Guest

    [snip]
    yeah, just to add to what victor said.

    If you are reading the char from a file, the range of a signed char is
    normally ( -128 -> 127 ), so 128 is not a valid value;

    You could trying using unsigned char....or even ints with appropriate
    masking.

    Yamin
    Yamin, Jun 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,059
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,172
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    16
    Views:
    7,283
    Mike Schilling
    Oct 12, 2005
  4. Replies:
    5
    Views:
    26,489
    Mike Schilling
    Mar 29, 2006
  5. Bo Peng
    Replies:
    13
    Views:
    13,267
    Siemel Naran
    Jul 18, 2004
Loading...

Share This Page