Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > An interesting blog

Reply
Thread Tools

An interesting blog

 
 
Keith Thompson
Guest
Posts: n/a
 
      07-31-2010
http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Bos) writes:
> jacob navia <(E-Mail Removed)> wrote:
>> Ben Bacarisse a écrit :

[...]
>> > There is a C point here. The original author (at least I think this is
>> > a quote) is mistaken about C. If m[5] does not exist, it would be
>> > wrong to expect NULL.
>> >

>> The C behavior should be an exception
>> (exception address violation).

>
> *******s. The C behaviour is undefined. Pay attention, please:
> _un_defined. Not "reasonably" defined, or POSIX-defined, or even
> navia-defined. _Un_-defined.


Didn't we recently have a debate about the meaning of "should"?

It's correct, of course, that the behavior of m[5] is undefined
if m is, or points to the first element of, an array with
insufficient elements. But it's perfectly reasonable to say that an
implementation *should* cause it to behave in some particular way.
(I'm only guessing that that's what jacob meant by the "C behavior".)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Ike Naar
Guest
Posts: n/a
 
      07-31-2010
In article <i2hsdk$djo$(E-Mail Removed)>,
jacob navia <(E-Mail Removed)> wrote:
>[snip]
>when I write m[5] and there's no m[5], I think there are only two
>things that are okay to happen.
>
>Either m[5] returns NULL (a passive indicator that there is no m[5],
>like you'd expect from C) or m[5] throws an exception (an aggressive
>indicator that there is no m[5], like you'd see in python).
>
>What is so difficult to understand there?


If NULL cannot be a value of the element type of m, then m[5] cannot
return NULL because it is of the wrong type (like, in the original
example, where m[5] is of type std::string, and thus cannot be NULL).

For instance, this test

if (m[5] == NULL) /* does m[5] exist ? */

would be a syntax error because the operands of ``=='' are of
incompatible type.

If NULL can be a value of the element type of m, then returning NULL
for a missing element is not particularly useful, because you would
not able to distinguish the situation "m[5] exists and contains NULL"
from "m[5] does not exists".
--
(E-Mail Removed)
SDF Public Access UNIX System - http://sdf.lonestar.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Blog form Net Programing and Blog IT competition zegga ASP .Net 0 08-01-2009 05:38 AM
The Switch Blog -->AL Wireless Networking 1 03-26-2005 02:31 AM
blog blog blog John Computer Information 0 02-13-2005 10:20 AM



Advertisments