Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: Non-null po...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 49 Topic 1099 of 1161
Post > Topic >>

Re: Non-null pointers in C/C++?

by "Wojtek Lerch" <Wojtek_L@[EMAIL PROTECTED] > May 24, 2008 at 06:15 PM

"Gordon Burditt" <gordonb.ll93b@[EMAIL PROTECTED]
> wrote in message 
news:clcm-20080523-0005@[EMAIL PROTECTED]
>>> and what happens if a null pointer gets passed as an argument to a
>>> non-null pointer parameter?
>>
>>It's undefined behaviour, but the compiler may be able to detect it and
>>issue a diagnostic.
>
> In that case, I think you just threw all the "safety" arguments out
> the window.  If you're going to claim "safety" benefits, the compiler
> needs to *CHECK*.  Of course, the issue is still there about what
> to do when the check fails.

Not *all* the safety arguments, just some of them.  Just because the 
behaviour is officially undefined doesn't mean that a good compiler can't 
insert opcodes to check for null and abort the program with an error 
message -- or, even better, have a switch to let you choose whether you
want 
the check or not.

I wouldn't expect this new feature to add more safety (or more syntactic 
complexity) to C than adding the "const" qualifier once did.  Despite the 
fact that C doesn't make it impossible to attempt to modify a 
const-qualified object by casting away the constness of a pointer, I don't

think anybody would claim that "const" has absolutely no safety benefits.

> In order to be useful, there has to be a way to convert a plain,
> old, ordinary, unsafe pointer to a non-null pointer, provided, of
> course that it p***** the check.

There's a difference between "useful" and "perfectly safe".  A feature
that 
makes programming a little safer can be useful, even if it doesn't make it

perfectly safe.

>   Here's a suggestion, but I'm sure
> someone will think the syntax is horrible.  ifnotnull is not a
> function, it's a syntax construct, sorta like if.  The assignment
> in ifnotnull(nnp = np) is only done if the value is not null.

Indeed, it does look pretty horrible.  But what feels worse to me is that
if 
you decide to go in that direction, you should also invent non-zeroable 
arithmetic types and similar syntax to protect division, and of course a 
non-indeterminate qualifier that could apply to any type to indicate that
an 
object cannot possibly contain an indeterminate value (and therefore, for 
instance, must be initialized if it's automatic).  Good luck with that.

....
>>And in a debug mode, it could also insert opcodes to
>>test for null at runtime.
>
> I'll even go so far as to say that in debug mode, it would be a
> good idea that converting *one* dangerous pointer to a not-null
> pointer should, ideally, involve checking *all* not-null pointers
> for being not null, to the extent possible.  This would at least
> include all of the not-null pointers with declarations in scope.

The C standard has no concept of "debug mode".  Any debug facilities are a

quality-of-implementation issue.

> Should we also forbid uninitialized not-null pointers?

Exactly, and what about pointers that point to an object that has gone out

of scope?

What about pointers inside a union?

My vote: if you're looking for a language with absolute safety, C is one
of 
the worst possible choices.  It will never make it impossible for you to 
shoot youself in the foot if you try; the best that can be done is to make

it more helpful in avoiding shooting yourself by accident.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 49 Posts in Topic:
Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-05-13 01:06:32 
Re: Non-null pointers in C/C++?
Francis Glassborow <fr  2008-05-15 11:00:31 
Re: Non-null pointers in C/C++?
"Wojtek Lerch"   2008-05-22 16:51:34 
Re: Non-null pointers in C/C++?
gordonb.ll93b@[EMAIL PROT  2008-05-23 15:57:23 
Re: Non-null pointers in C/C++?
"Wojtek Lerch"   2008-05-24 18:15:37 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-05-22 16:51:43 
Re: Non-null pointers in C/C++?
jameskuyper@[EMAIL PROTEC  2008-05-23 15:57:09 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-05-28 13:35:14 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-05-29 10:58:00 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-06-01 12:35:06 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-01 12:35:16 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-06-02 11:54:23 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-10 00:56:47 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-06-12 19:25:13 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-14 03:02:07 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-18 08:45:23 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-18 08:45:31 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-06-28 19:04:48 
Re: Non-null pointers in C/C++?
gordon@[EMAIL PROTECTED]   2008-07-04 01:45:57 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-07-08 21:18:29 
Re: Non-null pointers in C/C++?
gordonb.4ax5t@[EMAIL PROT  2008-07-10 13:02:14 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-07-12 18:10:36 
Re: Non-null pointers in C/C++?
gordonb.4dbn6@[EMAIL PROT  2008-07-13 10:55:33 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-07-20 15:07:13 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-07-21 18:28:00 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-07-23 22:51:02 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-07-25 12:15:29 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-08-02 12:34:34 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-08-07 15:01:26 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-08-11 19:05:20 
Re: Non-null pointers in C/C++?
blargg.h4g@[EMAIL PROTECT  2008-08-14 15:29:10 
Re: Non-null pointers in C/C++?
jameskuyper@[EMAIL PROTEC  2008-08-14 15:29:37 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-08-20 21:30:20 
Re: Non-null pointers in C/C++?
John Nagle <nagle@[EMA  2008-08-14 15:30:30 
Re: Non-null pointers in C/C++?
"Mabden" <Ma  2008-08-09 12:08:24 
Re: Non-null pointers in C/C++?
Jasen Betts <jasen@[EM  2008-07-20 15:07:47 
Re: Non-null pointers in C/C++?
"Angel Tsankov"  2008-07-21 18:28:13 
Re: Non-null pointers in C/C++?
Francis Glassborow <fr  2008-07-04 01:46:17 
Re: Non-null pointers in C/C++?
James Kuyper <jameskuy  2008-06-12 19:32:35 
Re: Non-null pointers in C/C++?
Philip Lantz <prl@[EMA  2008-06-14 03:01:41 
Re: Non-null pointers in C/C++?
=?ISO-8859-1?Q?Hans-Bernh  2008-05-15 11:00:41 
Re: Non-null pointers in C/C++?
"Wojtek Lerch"   2008-05-22 16:51:39 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-05-22 16:51:46 
Re: Non-null pointers in C/C++?
Jonathan Leffler <jlef  2008-05-24 18:15:49 
Re: Non-null pointers in C/C++?
gordonb.vehsx@[EMAIL PROT  2008-05-15 11:00:54 
Re: Non-null pointers in C/C++?
Eric Sosman <Eric.Sosm  2008-05-22 16:51:21 
Re: Non-null pointers in C/C++?
angel_tsankov <fn42551  2008-05-22 16:51:53 
Re: Non-null pointers in C/C++?
Matthias Buelow <mkb@[  2008-05-23 15:57:49 
Re: Non-null pointers in C/C++?
Roberto Waltman <usene  2008-06-10 00:57:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:44:18 CDT 2008.