a[i++] = j

K

Kojak

Le Fri, 20 Feb 2009 09:33:03 -0800 (PST),
saurabh29789 a écrit :
Is the behavior of

a[i++] = j;

and/or

a[++i] = j;

undefined??

Why should it be undefined ? It's perfectly legal.

Juste keep in mind that 2 lines differs slightly, depending
on what you expect (i++ vs. ++i).
 
J

jameskuyper

saurabh29789 said:
Is the behavior of

a[i++] = j;

and/or

a[++i] = j;

undefined??

That depends very much upon what 'a', 'i', and 'j' are. There's no
reason within either of those statements themselves why the behavior
should be undefined. However, consider:

#include <limits.h>

char *i = "Hello!"+6;
int a = 1;
float j = CHAR_MAX*2.0F;

With those definitions "a[i++] = j;" has undefined behavior for at
least two different reasons. If a, i, or j are macros, the list of
different ways in which something could go wrong is practically
endless.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top