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 21 of 49 Topic 1099 of 1142
Post > Topic >>

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

by gordonb.4ax5t@[EMAIL PROTECTED] (Gordon Burditt) Jul 10, 2008 at 01:02 PM

>> >So, there are no more questions about "unnullable"? If so, how can I
>>>propose the addition of unnullable to the C standard?
>>
>> I still claim that if there is no way to convert a nullable pointer
>> to an unnullable pointer (which includes a check for NULL and the
>> possibility of failure), you've missed about 99% of the problem
>> that unnullable pointers are supposed to solve (dealing with dynamic
>> memory allocation).
>
>How about this way (posted by me on this thread on June, 1st):
>
>void do_something()
>{
>        char* p = get_pointer_from_somewhere();
>
>        if (p == NULL)
>        {
>            // There's nothing to do with a null pointer here, so just 
>return
>            return;
>        }
>
>        unnullable char* r = (unnullable char*)p;
>        // Go ahead and work with r
>}

Ok, describe (preferably in standardese) under what cir***stances
the compiler *MUST* determine that p is not NULL at the declaration
of r.  If that one is too obvious, I can construct a maze of if and
switch statements that guarantee that p is not NULL when it arrives
at the declaration of r, but the compiler cannot prove that.

Also, the compiler needs to throw an error if the line "if (p ==
NULL)" gets changed to "if (q == NULL)" where q is declared elsewhere
but r is still initialized from p.

>> So far, I've seen mostly proposals to prohibit
>> trying to do such a conversion.
>>
>
>Why prohibiting such a conversion?!

Obviously you want to prohibit:
	unnullable char *r = NULL;
Some people apparently thought forcing a check was too messy, so
they want to prohibit converting from anything that *might* be null.
Some proposals wanted to only permit unnullable pointers to be
initialized from things that CANNOT be null (such as taking the
address of a variable).  That, IMHO, limits the use of it so much
that it's worthless.

You want to be able to take pointers from real-world functions that
can fail (e.g. malloc() and fopen()), *CHECK* them (no wimping out that
letting a null sneak in is "undefined behavior"), and then assign it to
an unnullable pointer.  Much of the problem of dereferencing NULL pointers
comes from the failure to include such checks.


>> Also, if you expect "unnullable" to do any good, it needs do***ented
>> behavior should a NULL manage to slip in where it's not wanted.
>
>Why do you expect that a NULL may slip in an unnullable pointer?! How do
you 
>image this happening? 

If you initialize an unnullable from the return value of a function
that can return NULL, and forget the NULL check, and don't mandate
that the compiler perform an actual check (not calling it "undefined
behavior"), a NULL could sneak in.  So you want to make sure that at
the time of the conversion, there IS such a check.  Preferably enforced
by syntax, so it won't even compile until you put in the check.

No existing code has unnullable pointers, so if you're modifying
the code to use them, it's easy to miss something.  That's a large
part of the reason for wanting them:  existing code tends to forget
the checks.  Also, there's the myth that "we've got plenty of memory,
malloc() will never fail".
-- 
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 Wed Aug 27 17:53:39 CDT 2008.