Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Problem with NULL in g++

Reply
Thread Tools

Re: Problem with NULL in g++

 
 
Gopi Subramanian
Guest
Posts: n/a
 
      06-24-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (tom_usenet) wrote in message news:<(E-Mail Removed)>...
> On 23 Jun 2003 05:22:14 -0700, (E-Mail Removed) (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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-24-2003
"Gopi Subramanian" <(E-Mail Removed)> wrote...
> (E-Mail Removed) (tom_usenet) wrote in message

news:<(E-Mail Removed)>...
> > On 23 Jun 2003 05:22:14 -0700, (E-Mail Removed) (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


 
Reply With Quote
 
 
 
 
Yamin
Guest
Posts: n/a
 
      06-24-2003
[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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
createImage sometime returns null and sometime returns non-null. vizlab Java 3 10-17-2007 11:21 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
difference between null object and null string gokul.b@gmail.com Java 16 10-12-2005 06:43 PM
VB.NET Null to SQL Null (ASP.NET 2.0 GridView) Kivak Wolf ASP .Net 2 06-28-2005 02:01 PM
Is there a null ostream (like /dev/null) in cpp? Bo Peng C++ 13 07-18-2004 07:17 PM



Advertisments