Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Dereference an array pointer... UB?

Reply
Thread Tools

Dereference an array pointer... UB?

 
 
Richard Heathfield
Guest
Posts: n/a
 
      02-16-2008
Peter Nilsson said:

<snip>

> As quickly as you can, please tell me which of the
> following functions has UB.


Both of them. (Both do illegal pointer comparisons.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      02-17-2008
Richard Heathfield <(E-Mail Removed)> wrote:
> Peter Nilsson said:
>
> <snip>
>
> > As quickly as you can, please tell me which of the
> > following functions has UB.

>
> Both of them. (Both do illegal pointer comparisons.)


Are you saying that because that's your "quickly as
you can" response, or because you genuinely think this
to be true?

If the latter, c&v for version 1 would be appreciated.

--
Peter
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      02-18-2008
Peter Nilsson said:

> Richard Heathfield <(E-Mail Removed)> wrote:
>> Peter Nilsson said:
>>
>> <snip>
>>
>> > As quickly as you can, please tell me which of the
>> > following functions has UB.

>>
>> Both of them. (Both do illegal pointer comparisons.)

>
> Are you saying that because that's your "quickly as
> you can" response, or because you genuinely think this
> to be true?


No, you're right - I read the article too quickly. Apologies.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Chris Torek
Guest
Posts: n/a
 
      02-28-2008
In article <(E-Mail Removed)>
Keith Thompson <(E-Mail Removed)> wrote:
>Here's something to chew on. It probably says something about the
>original question, but I'm not sure what.
>
>int main(void)
>{
> struct s {
> int x;
> int y[2];
> } ;
> volatile struct s obj = { 10, { 20, 30 } };
>
> obj; /* Computes and discards the value of obj.
> Must access obj.x, obj.y[0], and obj.y[1]. */


This seems reasonable, although I would be unsurprised to find
compilers that did not in fact access the three "int"s.

> obj.x; /* Computes and discards the value of obj.x.
> Must access obj.x. */


And must not access obj.y[0] and obj.y[1] (I believe).

> obj.y; /* Computes and discards the address of obj.y[0].
> Must this access obj.y[0] and obj.y[1]?
> *May* it do so?
> C&V? */


I think the answer to this is "no and no" but I cannot prove it.

If the answer *is* "no and no", I think this guarantees that the
OP's construct (not included in this follow-up) is strictly conforming.

> return 0;
>}

--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
 
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
Two dimentional array dereference in C Srinu C Programming 10 11-21-2007 04:22 AM
dereference an array problem craigandjeanne Perl Misc 3 06-01-2006 12:53 AM
lexical declaration and array dereference ko Perl Misc 3 08-27-2003 07:43 AM
Re: how to properly dereference STL list item Howard C++ 0 07-01-2003 05:46 PM
Re: how to properly dereference STL list item Jakob Bieling C++ 0 07-01-2003 05:45 PM



Advertisments