Hello,
What is the difference between null and NULL. Are x == null and x ==
NULL the same? The compiler is gcc 3.2.
Thanks. 24 19922
RHNewBie <as**@asdf.com> wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
NULL is defined as a null pointer constant by your implementation.
null isn't required by the standard to be defined in an implementation.
See c.l.c-faq section 5 http://www.eskimo.com/~scs/C-faq/top.html
Regards
Irrwahn
--
Great minds run in great circles.
RHNewBie <as**@asdf.com> wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
NULL is defined as a null pointer constant by your implementation.
null isn't required by the standard to be defined in an implementation.
See c.l.c-faq section 5 http://www.eskimo.com/~scs/C-faq/top.html
Regards
Irrwahn
--
Great minds run in great circles.
On Wed, 24 Sep 2003, RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
C language has a NULL but there is no null. When writing I use NULL to
indicate the macro defined in <stdlib.h> and when discussing pointers. I
use null when discussing the null character. By null character I am
referring to '\0'.
With that semantics out of the way, if you are asking for the difference
between (x == '\0') and (x == NULL) it would depend on what x is. Off the
top of my head, they will evaluate to the same result for all x. I,
personally, use (x == '\0') if x is a char or int and (x == NULL) if x is
a pointer. For everything else you'd have to consider whether the
comparison is valid and how things will be converted or promoted.
--
darrell at cs dot toronto dot edu
or
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}
RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
Thanks.
Depends on how you have defined "NULL" and "null". These may or may not
be defined in some include file that you include.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
On Wed, 24 Sep 2003, RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
C language has a NULL but there is no null. When writing I use NULL to
indicate the macro defined in <stdlib.h> and when discussing pointers. I
use null when discussing the null character. By null character I am
referring to '\0'.
With that semantics out of the way, if you are asking for the difference
between (x == '\0') and (x == NULL) it would depend on what x is. Off the
top of my head, they will evaluate to the same result for all x. I,
personally, use (x == '\0') if x is a char or int and (x == NULL) if x is
a pointer. For everything else you'd have to consider whether the
comparison is valid and how things will be converted or promoted.
--
darrell at cs dot toronto dot edu
or
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}
RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
Thanks.
Depends on how you have defined "NULL" and "null". These may or may not
be defined in some include file that you include.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
Thanks.
Depends on how you have defined "NULL" and "null". These may or may not
be defined in some include file that you include.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
Thanks.
Depends on how you have defined "NULL" and "null". These may or may not
be defined in some include file that you include.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
"RHNewBie" <as**@asdf.com> wrote in message What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
NULL is the ANSI way of declaring a pointer which is known to be invalid.
ptr = NULL;
and
ptr = 0;
are equivalent.
It is annoying if your compiler comes with a header that declares "null"
because of the possibility of confusion. "null" may well be decared the same
as NULL, or there may be some subtle difference, for instance "null" might
not be cast to a void * type. You need to check your compiler documentation
for details.
"RHNewBie" <as**@asdf.com> wrote in message What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
NULL is the ANSI way of declaring a pointer which is known to be invalid.
ptr = NULL;
and
ptr = 0;
are equivalent.
It is annoying if your compiler comes with a header that declares "null"
because of the possibility of confusion. "null" may well be decared the same
as NULL, or there may be some subtle difference, for instance "null" might
not be cast to a void * type. You need to check your compiler documentation
for details.
"Malcolm" <ma*****@55bank.freeserve.co.uk> writes: It is annoying if your compiler comes with a header that declares "null" because of the possibility of confusion. "null" may well be decared the same as NULL, or there may be some subtle difference, for instance "null" might not be cast to a void * type. You need to check your compiler documentation for details.
The compiler is not allowed to declare `null' in any of the
standard header. `null' is not part of the reserved namespace.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
"Malcolm" <ma*****@55bank.freeserve.co.uk> writes: It is annoying if your compiler comes with a header that declares "null" because of the possibility of confusion. "null" may well be decared the same as NULL, or there may be some subtle difference, for instance "null" might not be cast to a void * type. You need to check your compiler documentation for details.
The compiler is not allowed to declare `null' in any of the
standard header. `null' is not part of the reserved namespace.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Irrwahn Grausewitz <ir*****************@freenet.de> writes: RHNewBie <as**@asdf.com> wrote:
Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2. NULL is defined as a null pointer constant by your implementation. null isn't required by the standard to be defined in an implementation.
`null' is required not to be defined by an implementation. It is
not part of the reserved namespace.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Irrwahn Grausewitz <ir*****************@freenet.de> writes: RHNewBie <as**@asdf.com> wrote:
Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2. NULL is defined as a null pointer constant by your implementation. null isn't required by the standard to be defined in an implementation.
`null' is required not to be defined by an implementation. It is
not part of the reserved namespace.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Darrell Grainger wrote: On Wed, 24 Sep 2003, RHNewBie wrote:
Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
C language has a NULL but there is no null. When writing I use NULL to indicate the macro defined in <stdlib.h> and when discussing pointers. I use null when discussing the null character. By null character I am referring to '\0'.
With that semantics out of the way, if you are asking for the difference between (x == '\0') and (x == NULL) it would depend on what x is. Off the top of my head, they will evaluate to the same result for all x.
if x is of type int and NULL is ((void*)0),
then the result of the comparison is not defined by the standard.
--
pete
"Ben Pfaff" <bl*@cs.stanford.edu> wrote in message
news:87************@pfaff.stanford.edu... "Malcolm" <ma*****@55bank.freeserve.co.uk> writes:
It is annoying if your compiler comes with a header that declares "null" because of the possibility of confusion. "null" may well be decared the
same as NULL, or there may be some subtle difference, for instance "null"
might not be cast to a void * type. You need to check your compiler
documentation for details.
The compiler is not allowed to declare `null' in any of the standard header. `null' is not part of the reserved namespace.
IOW, a conforming implementation must accept something like:
#include <stdio.h>
static int new( int class, int object )
{
return class - object;
}
int main(void)
{
int null = 12;
int instanceof = 54;
printf("%d\n", new(instanceof, null) );
return 0;
}
? (assuming I've not introduced an unrelated error)
BruceS <no****@nospam.net> scribbled the following: "Ben Pfaff" <bl*@cs.stanford.edu> wrote in message news:87************@pfaff.stanford.edu... "Malcolm" <ma*****@55bank.freeserve.co.uk> writes: > It is annoying if your compiler comes with a header that declares "null" > because of the possibility of confusion. "null" may well be decared the same > as NULL, or there may be some subtle difference, for instance "null" might > not be cast to a void * type. You need to check your compiler documentation > for details. The compiler is not allowed to declare `null' in any of the standard header. `null' is not part of the reserved namespace.
IOW, a conforming implementation must accept something like:
#include <stdio.h>
static int new( int class, int object ) { return class - object; }
int main(void) { int null = 12; int instanceof = 54;
printf("%d\n", new(instanceof, null) ); return 0; }
? (assuming I've not introduced an unrelated error)
Yes. The implementation is allowed to reserve these kind of names
for itself:
- anything starting with "mem" or "str" and including zero or more
lowercase letters after that
- anything starting with "E" and including one or more uppercase
letters after that
- anything starting with an underscore
Other than those three, you're free to use any names you please, as
long as they don't contradict with standard names or keywords.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft
Joona I Palaste <pa*****@cc.helsinki.fi> scribbled the following: Yes. The implementation is allowed to reserve these kind of names for itself: - anything starting with "mem" or "str" and including zero or more lowercase letters after that
Oops. As well as "mem" and "str", the "is" and "to" prefices are also
reserved.
- anything starting with "E" and including one or more uppercase letters after that - anything starting with an underscore Other than those three, you're free to use any names you please, as long as they don't contradict with standard names or keywords.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"It was, er, quite bookish."
- Horace Boothroyd
In <3F**********@mindspring.com> pete <pf*****@mindspring.com> writes: Darrell Grainger wrote: On Wed, 24 Sep 2003, RHNewBie wrote:
> Hello, > What is the difference between null and NULL. Are x == null and x == > NULL the same? The compiler is gcc 3.2.
C language has a NULL but there is no null. When writing I use NULL to indicate the macro defined in <stdlib.h> and when discussing pointers. I use null when discussing the null character. By null character I am referring to '\0'.
With that semantics out of the way, if you are asking for the difference between (x == '\0') and (x == NULL) it would depend on what x is. Off the top of my head, they will evaluate to the same result for all x.
if x is of type int and NULL is ((void*)0), then the result of the comparison is not defined by the standard.
The standard actually requires a diagnostic in this case (constraint
violation).
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
On Wed, 24 Sep 2003 19:58:16 GMT, "Fred L. Kleinschmidt"
<fr*****************@boeing.com> wrote in comp.lang.c:
RHNewBie wrote: Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2.
Thanks.
Depends on how you have defined "NULL" and "null". These may or may not be defined in some include file that you include.
NULL is required to be defined in a number of standard C headers. It
produces undefined behavior to try to define it in a program that
includes any of the standard headers defining it.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote in comp.lang.c: BruceS <no****@nospam.net> scribbled the following: "Ben Pfaff" <bl*@cs.stanford.edu> wrote in message news:87************@pfaff.stanford.edu... "Malcolm" <ma*****@55bank.freeserve.co.uk> writes: > It is annoying if your compiler comes with a header that declares "null" > because of the possibility of confusion. "null" may well be decared the same > as NULL, or there may be some subtle difference, for instance "null" might > not be cast to a void * type. You need to check your compiler documentation > for details.
The compiler is not allowed to declare `null' in any of the standard header. `null' is not part of the reserved namespace.
IOW, a conforming implementation must accept something like:
#include <stdio.h>
static int new( int class, int object ) { return class - object; }
int main(void) { int null = 12; int instanceof = 54;
printf("%d\n", new(instanceof, null) ); return 0; }
? (assuming I've not introduced an unrelated error)
Yes. The implementation is allowed to reserve these kind of names for itself:
Sorry, but all three of these are just a little bit wrong. I've
pasted in text from the current standard (but it has been the same
since ANSI 89):
- anything starting with "mem" or "str" and including zero or more lowercase letters after that
"7.26.11 String handling <string.h>
1 Function names that begin with str, mem, or wcs and a lowercase
letter may be added to the declarations in the <string.h> header."
So it's "one or more", not "zero or more".
- anything starting with "E" and including one or more uppercase letters after that
"7.26.3 Errors <errno.h>
1 Macros that begin with E and a digit or E and an uppercase letter
may be added to the declarations in the <errno.h> header."
So it's also E followed by a digit. E2 is reserved, for example.
- anything starting with an underscore
"7.1.3 Reserved identifiers
1 Each header declares or defines all identifiers listed in its
associated subclause, and optionally declares or defines identifiers
listed in its associated future library directions subclause and
identifiers which are always reserved either for any use or for use as
file scope identifiers.
— All identifiers that begin with an underscore and either an
uppercase letter or another underscore are always reserved for any
use.
— All identifiers that begin with an underscore are always reserved
for use as identifiers with file scope in both the ordinary and tag
name spaces."
So the identifiers _1, _2, and so on, are in the user namespace, as
are _local and such, with a lower case letter in block scope
variables, and so on.
Other than those three, you're free to use any names you please, as long as they don't contradict with standard names or keywords.
Joona, are you familiar with the American slang expression, "Close,
but no cigar"?
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jack Klein <ja*******@spamcop.net> scribbled the following: On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <pa*****@cc.helsinki.fi> wrote in comp.lang.c: Yes. The implementation is allowed to reserve these kind of names for itself:
Sorry, but all three of these are just a little bit wrong. I've pasted in text from the current standard (but it has been the same since ANSI 89):
- anything starting with "mem" or "str" and including zero or more lowercase letters after that
"7.26.11 String handling <string.h> 1 Function names that begin with str, mem, or wcs and a lowercase letter may be added to the declarations in the <string.h> header."
So it's "one or more", not "zero or more".
- anything starting with "E" and including one or more uppercase letters after that
"7.26.3 Errors <errno.h> 1 Macros that begin with E and a digit or E and an uppercase letter may be added to the declarations in the <errno.h> header."
So it's also E followed by a digit. E2 is reserved, for example.
- anything starting with an underscore
"7.1.3 Reserved identifiers 1 Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers. — All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. — All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces."
So the identifiers _1, _2, and so on, are in the user namespace, as are _local and such, with a lower case letter in block scope variables, and so on.
Other than those three, you're free to use any names you please, as long as they don't contradict with standard names or keywords.
Joona, are you familiar with the American slang expression, "Close, but no cigar"?
Yes I am. It comes from old American pinball-type machines where the
machine offered minuscule cash prizes, but the main prize was a
luxurious cigar. Thanks for the corrections.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
- Dr. Michael Hfuhruhurr
In <bk**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes: Yes. The implementation is allowed to reserve these kind of names for itself: - anything starting with "mem" or "str" and including zero or more lowercase letters after that
s/zero/one
Other than those three, you're free to use any names you please, as long as they don't contradict with standard names or keywords.
Nope, the list of reserved prefixes is much longer. "is" and "to" are
particularly easy to be accidentally used: "iso_name" or "toxicity" are
perfectly natural and innocent looking identifiers.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dmitry D |
last post by:
Hi,
I'm new to C++ (started learning in the beginning of this summer), and I
have the following question (sorry if it sounds stupid):
In many code samples and source files, I see NULL expression...
|
by: Ken |
last post by:
Hi all. When referring to a null pointer constant in C++, is there
any reason to prefer using 0 over a macro called NULL that is defined
to be 0?
Thanks!
Ken
|
by: Jason Curl |
last post by:
I've been reading this newsgroup for some time and now I am thoroughly
confused over what NULL means.
I've read a NULL pointer is zero (or zero typecast as a void pointer),
others say it's...
|
by: Mikhail Teterin |
last post by:
Hello!
Consider the following simple accessor function:
typedef struct {
int i;
char name;
} MY_TYPE;
const char *
|
by: Adam Clauss |
last post by:
Basically, my question is in terms of performance and the garbage collector -
Is there any difference between
a) letting a variable simply go out of scope
b) explicity setting it to null once I am...
|
by: Shwetabh |
last post by:
Hi,
My question is, is there any difference between a NULL and a Blank
(Unknown, Not Applicable) field in MS SQL or are they the same?
Awaiting your comments,
Regards
|
by: Jiho Han |
last post by:
Here's the issue.
You have a class,
Class Person
{
public int id;
public string firstname;
public string lastname;
}
|
by: valentin tihomirov |
last post by:
As explained in "Using pointers vs. references"
http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca ,
the...
|
by: iceman19860106 |
last post by:
hello everyone!
what is the difference between NULL and 0 in C language?
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |