473,672 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NULL

Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?

-X
Jul 19 '05 #1
48 12525
Agent Mulder wrote:
Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?


NULL is almost certainly defined as
#define NULL 0

So why not? It's just substituted text.

Jul 19 '05 #2

"Dimitris Kamenopoulos" <dk*********@cs lab.ece.ntua.gr > wrote in message
news:bj******** ***@ulysses.noc .ntua.gr...
Agent Mulder wrote:
Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?


NULL is almost certainly defined as
#define NULL 0

So why not? It's just substituted text.


I think this illustrates what a waste of time NULL is. Its pretending to be
a special pointer value, but really it just zero. Don't pretend, use zero.

john
Jul 19 '05 #3

"Agent Mulder" <mb************ *******@home.nl > wrote in message news:bj******** **@news3.tilbu1 .nb.home.nl...
Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

It's valid in C++, but kind of silly. C++ requires NULL to be a macro
for an integer constant expression evaluating to zero.

Note however, that it's not a good idea in C. C allows (stupidly in my
opinion) the addition of a (void*) cast on the value 0. This won't allow
assignment to numeric types.
Jul 19 '05 #4

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:bj******** ****@ID-196037.news.uni-berlin.de...
> NULL is almost certainly defined as
#define NULL 0

So why not? It's just substituted text.


I think this illustrates what a waste of time NULL is. Its pretending to

be a special pointer value, but really it just zero. Don't pretend, use zero.


Yeah, this is one of those things that seems to obfuscate with no apparent
benefit. I remember seeing some code once where someone who was taught to
define constants for "Everything " got carried away.

#define ONE 1

God, can you imagine? One of the benefits of using a constant is that if a
value ever changes, it can be changed in one place, not many places. What
if the value actually did change?
Jul 19 '05 #5
> > > NULL is almost certainly defined as
#define NULL 0

So why not? It's just substituted text.

I think this illustrates what a waste of time NULL is. Its pretending to

be
a special pointer value, but really it just zero. Don't pretend, use

zero.
Yeah, this is one of those things that seems to obfuscate with no apparent
benefit. I remember seeing some code once where someone who was taught to
define constants for "Everything " got carried away.

#define ONE 1

God, can you imagine?


Yes I can, I know of someone who used macro's to turn a C compiler into a
(sort of) Pascal compiler. Unfortunately he was the only one who could make
sense out of his code. Macros are the ideal tool to obfuscate code, and some
people really do love this kind of thing.

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl

Jul 19 '05 #6
Peter van Merkerk wrote:
[SNIP]
#define ONE 1

God, can you imagine?


Yes I can, I know of someone who used macro's to turn a C compiler
into a (sort of) Pascal compiler. Unfortunately he was the only one
who could make sense out of his code. Macros are the ideal tool to
obfuscate code, and some people really do love this kind of thing.


Hehe. A college of mine turned C into Korn shell. His code was something
like this:

if (..) then
fi

It took me (not knowing UNIX at all at that time) half an hour just to learn
what he is doing by reading his obfuscation header.

--
WW aka Attila
Jul 19 '05 #7

"White Wolf" <wo***@freemail .hu> wrote in message news:bj******** **@phys-news1.kolumbus. fi...
Peter van Merkerk wrote:
[SNIP]
#define ONE 1

God, can you imagine?


Yes I can, I know of someone who used macro's to turn a C compiler
into a (sort of) Pascal compiler. Unfortunately he was the only one
who could make sense out of his code. Macros are the ideal tool to
obfuscate code, and some people really do love this kind of thing.


Hehe. A college of mine turned C into Korn shell. His code was something
like this:

if (..) then
fi


If you ever saw what the Bourne shell (and certain of Steve's other programs)
looked like. He spent a lot of time making C look like ALGOL or something.

Jul 19 '05 #8
>> #define ONE 1

God, can you imagine?
Yes I can, I know of someone who used macro's to turn a C compiler into a
(sort of) Pascal compiler. Unfortunately he was the only one who could make
sense out of his code. Macros are the ideal tool to obfuscate code, and somepeople really do love this kind of thing.


Yes. It was the THE fun in assembler. Building
your own lego. In C++, #define is among the
more ugly features.

-X
Jul 19 '05 #9
John Harrison wrote:
"Dimitris Kamenopoulos" <dk*********@cs lab.ece.ntua.gr > wrote in message
news:bj******** ***@ulysses.noc .ntua.gr...
Agent Mulder wrote:

Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?
NULL is almost certainly defined as
#define NULL 0

So why not? It's just substituted text.

I think this illustrates what a waste of time NULL is. Its pretending to be
a special pointer value, but really it just zero. Don't pretend, use zero.


IMHO you are wrong. NULL is provided for readability and to express an
idea that is not representable by a number. We don't care what the
number is, what we care is if the pointer is labeled as invalid.

Macro definitions of constants is not just so that you can change the
definition in a single place, but also to convey ideas about the code.

john

Jul 19 '05 #10

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

Similar topics

26
45409
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.) How can I achieve this? I suppose I would get the most-hated "table/view is changing, trigger/function may not see it" error if I tried to write a trigger that checks the uniqueness of non-null values upon insert/update.
3
2115
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 Perl, and Nulls have started to bother me greatly. The first issue is, as far as I understand it, a column should be NOT NULL if it is necessary (required) data. Now, if a column doesn't have to be NOT NULL; that is, it's not _required_ data,...
5
4241
by: Mike MacSween | last post by:
This as the row source for a combo: SELECT qryRole.RoleID, qryRole.Role FROM qryRole WHERE (((qryRole.RoleID) Not In (SELECT RoleID FROM qryRoleEvent INNER JOIN qryEvent ON qryRoleEvent.EventID = qryEvent.EventID WHERE ProdID = Forms!frmProductions!ProdID))) ORDER BY qryRole.Role; If there is just one RoleID with a null value in the subquery then the main
3
7649
by: sathyashrayan | last post by:
The standard confirms that the following initialization of a struct struct node { --- --- } struct node var = {NULL};
102
5976
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" ( i am talking of unix machine ) while trying to read that location. Then how can i distinguish between a NULL pointer and an invalid location ? Is this essential that NULL pointer should not point to any of the location in the virtual address...
29
3737
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...
5
24698
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
64
3902
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")? - AFAIK C allows "null pointers" to be represented differently then "all bits 0". Is this correct? - AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work just like `void* p=NULL'. Is this correct?
0
5376
by: Aaron Morton | last post by:
I'm working on a IHttpModule that handles the PreSendRequestHeaders event from the HttpApplication, if the event is raised after EndRequest then HttpContext.Current is null. If it is raised before EndRequest (by turning response buffering off) then HttpContext.Current is set. To repo add the following to Global.asax protected void Application_PreSendRequestHeaders(object sender, EventArgs e) {...
46
3659
by: lovecreatesbea... | last post by:
Do you prefer malloc or calloc? p = malloc(size); Which of the following two is right to get same storage same as the above call? p = calloc(1, size); p = calloc(size, 1);
0
8406
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
8609
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
7449
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6240
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5707
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
4419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2821
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
2064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1819
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.