473,890 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

null and NULL: is there any difference?

Hello,
What is the difference between null and NULL. Are x == null and x ==
NULL the same? The compiler is gcc 3.2.

Thanks.

Nov 13 '05
24 20151
On Wed, 24 Sep 2003 19:58:16 GMT, "Fred L. Kleinschmidt"
<fr************ *****@boeing.co m> 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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #21
On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <pa*****@cc.hel sinki.fi>
wrote in comp.lang.c:
BruceS <no****@nospam. net> scribbled the following:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"Malcolm" <ma*****@55bank .freeserve.co.u k> 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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #22
Jack Klein wrote:
Joona, are you familiar with the American slang expression, "Close,
but no cigar"?


I associate that expression with this type of device:

http://www.rental-world.com/images/C...%20Striker.jpg
Nov 13 '05 #23
Jack Klein <ja*******@spam cop.net> scribbled the following:
On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <pa*****@cc.hel sinki.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.hel sinki.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
Nov 13 '05 #24
In <bk**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.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
Nov 13 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
25779
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 being used (for example, int* someInt=NULL; ). I used similar initialization myself, and it works fine even if I don't define NULL. But what is "NULL" exactly? Is it a constant defined by compiler? Is there any difference between the following two...
69
7483
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
29
3786
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 compiler dependent (and that NULL might be anything, but it is always NULL). The source snippet is below. The question is: - When I use calloc to allocate a block of memory, preinitialising it to zero, is this equivalent (and portable C) to...
99
5236
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
1793
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 done with it I have no particular reason to think that b) would gain me anything, but I thought maybe it would be a sure sign to the garbage collector that Yes, you can go ahead and remove the object. Thanks!
4
32747
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
13
1772
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; }
76
4745
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 pointers are allowed to be null, while references must refer an existing variable of required type. The null is normally used for making optional parameters. But there is no way to pass null reference in C#. Something is missing.
5
6923
by: iceman19860106 | last post by:
hello everyone! what is the difference between NULL and 0 in C language?
0
9979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6058
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.