C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to initialize a pointer in c++,

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
海风
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: How to initialize a pointer in c++, Reply with quote



How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

but if i base on lunix operate system, is it correct also.

I think i shoud use 0, for example,
char * szName =0;
is it more general?

thank in advanced
Back to top
Jonathan Mcdougall
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote



Ian Collins wrote:
Quote:
海风 wrote:
How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

Not a standard header.

Use NULL.

Or just 0.


Jonathan
Back to top
Ian Collins
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote



海风 wrote:
Quote:
How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

Not a standard header.


Use NULL.

--
Ian Collins.
Back to top
Gernot Frisch
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote

"Ian Collins" <ian-news (AT) hotmail (DOT) com> schrieb im Newsbeitrag
news:4enhpqF1fles1U6 (AT) individual (DOT) net...
Quote:
benben wrote:
Ian Collins wrote:

海风 wrote:

How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

Not a standard header.

Use NULL.


NULL is not defined by default.

What is? NULL is part of standard C++, null isn't.

There's nothing wrong with using 0, it's all a matter of style.

#define NULL 0L

NULL indicates that the variable is a pointer. An NULL is a pointer to
invalid memory.
Back to top
Ian Collins
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote

benben wrote:
Quote:
Ian Collins wrote:

海风 wrote:

How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

Not a standard header.

Use NULL.


NULL is not defined by default.

What is? NULL is part of standard C++, null isn't.


There's nothing wrong with using 0, it's all a matter of style.

--
Ian Collins.
Back to top
benben
Guest





PostPosted: Wed Jun 07, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote

Ian Collins wrote:
Quote:
海风 wrote:
How to initialize a pointer in c++,
Mostly, I use null, for example,
char * szName = null;
However, if i compile it without including afxdisp.h
, .net compiler tell me that the identifier is not declared.

Not a standard header.

Use NULL.


NULL is not defined by default.

Ben
Back to top
red floyd
Guest





PostPosted: Fri Jun 09, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote

marius lazer wrote:
Quote:
Noah Roberts wrote:

It can't be both, which is it? Does the standard not define NULL or is
it against the standard to define NULL as (void*)0?

The C++ standard does not define NULL, but most compiler or system
header files do (leftover from K&R C). If your NULL is defined as
(void*)0 or 0L or whatever other than plain 0 do not use it! The
standard states to use unadorned 0 so that's what I've been doing since
'93.


Actually, footnote 180 to 18.1/4 says that 0L is legit. However
(void*)0 is specifically banned.
Back to top
Richard Herring
Guest





PostPosted: Mon Jun 12, 2006 9:10 am    Post subject: Re: How to initialize a pointer in c++, Reply with quote

In message <EJxig.22086$VE1.13261 (AT) newssvr14 (DOT) news.prodigy.com>, Phlip
<phlipcpp (AT) yahoo (DOT) com> writes
Quote:
marius lazer wrote:

Yes, but these are the "old" C header files wrapped in the std
namespace. C++ has no need for NULL.

All code should clearly state its intent to the reader. if(p) may be fun and
cute, but if(NULL == p) clearly states its intent.

But, depending on what your p actually represents, the ownership model,

etc. etc., one of the following
if (is_a_valid_pointer(p))
if (!has_expired(p))
if (is_allocated(p))
would be clearer still, and also avoids the problem that caused you to
write your comparison the unnatural way round. Where do you draw the
line?

Personally I'd consider if (p) to be a natural idiom of the language,
and therefore perfectly clear and, moreover, concise.

--
Richard Herring
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.