If I need a NULL value, should I define it myself, or include a standard
header of some kind?
I've been including <cstdio> whenever I need it, but is it just as good
to do something like
#define NULL (void *)0
Thanks,
--John Ratliff 4 5199
John Ratliff wrote: If I need a NULL value, should I define it myself, or include a standard header of some kind?
I've been including <cstdio> whenever I need it, but is it just as good to do something like
#define NULL (void *)0
Thanks,
--John Ratliff
You have two options:
#include <cstdlib>
or, just use 0.
HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
John Ratliff wrote: If I need a NULL value, should I define it myself, or include a standard header of some kind?
Usually including <cstdlib> takes care of that.
I've been including <cstdio> whenever I need it, but is it just as good to do something like
#define NULL (void *)0
No, you mustn't do that. If you're compiling C++, you are allowed to do
#define NULL 0
but no (void*) nonsense.
V
* John Ratliff: If I need a NULL value, should I define it myself,
No.
or include a standard header of some kind?
You don't need to, just write
0
I've been including <cstdio> whenever I need it,
If you just need the name NULL it would be more natural to use [cstddef],
since it doesn't drag in some many other definitions.
but is it just as good to do something like
#define NULL (void *)0
It's not valid to redefine a standard macro, and besides, the definition in
C++ isn't "(void*)0", but typically just "0": §18.1/4 note 180 "Possible
definitions include 0 and 0L, but not (void*)0" (see §4.10/1 for details).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Alf P. Steinbach wrote: * John Ratliff:
If I need a NULL value, should I define it myself,
No.
or include a standard header of some kind?
You don't need to, just write
0 I've been including <cstdio> whenever I need it,
If you just need the name NULL it would be more natural to use [cstddef], since it doesn't drag in some many other definitions. but is it just as good to do something like
#define NULL (void *)0
It's not valid to redefine a standard macro, and besides, the definition in C++ isn't "(void*)0", but typically just "0": §18.1/4 note 180 "Possible definitions include 0 and 0L, but not (void*)0" (see §4.10/1 for details).
Thanks. This is what I wanted to know.
--John Ratliff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Morgan |
last post by:
In an SQL statement which concatenates several fields I get a null
value returned if any one of the fields are null.
Is this to be expected?
For example :
SELECT tblMember.memberAddress + '...
|
by: iStrain |
last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the
answer in a way I can make sense out of. I know I should get this, but
so far no way...
I'm creating tables and doing queries in...
|
by: Lyn |
last post by:
I am trying to get my head around the concept of default, special or empty
values that appear in Access VBA, depending on data type. The Access Help
is not much (help), and the manual that I have...
|
by: junky_fellow |
last post by:
Can 0x0 be a valid virtual address in the address space
of an application ?
If it is valid, then the location pointed by a NULL pointer
is also valid and application should not receive "SIGSEGV"...
|
by: Mikhail Teterin |
last post by:
Hello!
Consider the following simple accessor function:
typedef struct {
int i;
char name;
} MY_TYPE;
const char *
|
by: Federico Balbi |
last post by:
Hi,
I was wondering if PGSQL has a function similar to binary_checksum() of
MS SQL Server 2000. It is pretty handy when it comes to compare rows of
data instead of having to write long boolean...
|
by: yossi.kreinin |
last post by:
Hi!
There is a system where 0x0 is a valid address, but 0xffffffff isn't.
How can null pointers be treated by a compiler (besides the typical
"solution" of still using 0x0 for "null")?
-...
|
by: Mark A |
last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP
11).
Using the SAMPLE database, tables EMP and EMLOYEE.
In the followng stored procedure, 2 NULL columns (COMM) are...
|
by: khan |
last post by:
Hi,
I read that pointer representation can non-zero bit pattern, machine
specific.Compiler when comes accross value '0' in pointer context,
converts it to machine specific null pointer...
|
by: ADezii |
last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
|
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:
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |