Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Implementation-defined behaviour

Reply
Thread Tools

Implementation-defined behaviour

 
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-28-2008
AFAIK the following is implementation-defined behaviour, am I right?:


#include <stdio.h>


int main(void)
{
int n= 0;

printf("%d\n", n++);


return 0;
}
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      03-28-2008
Ioannis Vranos wrote:

> AFAIK the following is implementation-defined behaviour, am I right?:
>
> #include <stdio.h>
>
> int main(void)
> {
> int n= 0;
> printf("%d\n", n++);
> return 0;
> }


I don't think so.

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      03-28-2008
Ioannis Vranos wrote:
> AFAIK the following is implementation-defined behaviour, am I right?:
>
>
> #include <stdio.h>
>
>
> int main(void)
> {
> int n= 0;
>
> printf("%d\n", n++);
>
>
> return 0;
> }


Only by quibbles: the form of "successful termination"
returned to the host environment is implementation-defined,
the actual new-line representation written to stdout in
response to the '\n' is implementation-defined, and things
of that sort.

What aspect do you believe is not Standard-defined?

--
Eric Sosman
lid
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-28-2008
santosh wrote:
> Ioannis Vranos wrote:
>
>> AFAIK the following is implementation-defined behaviour, am I right?:
>>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> int n= 0;
>> printf("%d\n", n++);
>> return 0;
>> }

>
> I don't think so.


There are similar examples at 2.12 of K&R2.


Two quotes from there:

"printf("%d %d\n", ++n, power(2, n)); /* WRONG */"


"One unhappy situation is typified by the statement

a[i]= i++;"
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-28-2008
Eric Sosman wrote:
> Ioannis Vranos wrote:
>> AFAIK the following is implementation-defined behaviour, am I right?:
>>
>>
>> #include <stdio.h>
>>
>>
>> int main(void)
>> {
>> int n= 0;
>>
>> printf("%d\n", n++);
>>
>>
>> return 0;
>> }

>
> Only by quibbles: the form of "successful termination"
> returned to the host environment is implementation-defined,
> the actual new-line representation written to stdout in
> response to the '\n' is implementation-defined, and things
> of that sort.
>
> What aspect do you believe is not Standard-defined?



I am talking about the implementation-defined behaviour of the printf()
call described at 2.12 of K&R2.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-28-2008
Ioannis Vranos wrote:

> santosh wrote:
>> Ioannis Vranos wrote:
>>
>>> AFAIK the following is implementation-defined behaviour, am I
>>> right?:
>>>
>>> #include <stdio.h>
>>>
>>> int main(void)
>>> {
>>> int n= 0;
>>> printf("%d\n", n++);
>>> return 0;
>>> }

>>
>> I don't think so.

>
> There are similar examples at 2.12 of K&R2.
>
>
> Two quotes from there:
>
> "printf("%d %d\n", ++n, power(2, n)); /* WRONG */"
>
>
> "One unhappy situation is typified by the statement
>
> a[i]= i++;"


Well these examples are different from what you have shown above. The
first example above invokes unspecified behaviour while the second one
invokes undefined behaviour. The example in your first post does
neither as far as I can see.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      03-28-2008
Ioannis Vranos wrote:
> Eric Sosman wrote:
>> Ioannis Vranos wrote:
>>> AFAIK the following is implementation-defined behaviour, am I right?:
>>>
>>>
>>> #include <stdio.h>
>>>
>>>
>>> int main(void)
>>> {
>>> int n= 0;
>>>
>>> printf("%d\n", n++);
>>>
>>>
>>> return 0;
>>> }

>> Only by quibbles: the form of "successful termination"
>> returned to the host environment is implementation-defined,
>> the actual new-line representation written to stdout in
>> response to the '\n' is implementation-defined, and things
>> of that sort.
>>
>> What aspect do you believe is not Standard-defined?

>
>
> I am talking about the implementation-defined behaviour of the printf()
> call described at 2.12 of K&R2.
>

There's nothing wrong with your example, the one you cite is completely
different. If you had tried to use n again in the printf, you would hit UB.

--
Ian Collins.
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-28-2008
Ian Collins wrote:
> Ioannis Vranos wrote:
>> Eric Sosman wrote:
>>> Ioannis Vranos wrote:
>>>> AFAIK the following is implementation-defined behaviour, am I right?:
>>>>
>>>>
>>>> #include <stdio.h>
>>>>
>>>>
>>>> int main(void)
>>>> {
>>>> int n= 0;
>>>>
>>>> printf("%d\n", n++);
>>>>
>>>>
>>>> return 0;
>>>> }
>>> Only by quibbles: the form of "successful termination"
>>> returned to the host environment is implementation-defined,
>>> the actual new-line representation written to stdout in
>>> response to the '\n' is implementation-defined, and things
>>> of that sort.
>>>
>>> What aspect do you believe is not Standard-defined?

>>
>> I am talking about the implementation-defined behaviour of the printf()
>> call described at 2.12 of K&R2.
>>

> There's nothing wrong with your example, the one you cite is completely
> different. If you had tried to use n again in the printf, you would hit UB.



So, printf("%d "%d\n", x++, x++); invokes implementation-defined
behaviour, while printf("%d\n", x++); doesn't invoke
implementation-defined behaviour?

 
Reply With Quote
 
Dann Corbit
Guest
Posts: n/a
 
      03-28-2008
"Ioannis Vranos" <> wrote in message
news:fshjmg$1avp$...
> AFAIK the following is implementation-defined behaviour, am I right?:
>
>
> #include <stdio.h>
>
>
> int main(void)
> {
> int n= 0;
>
> printf("%d\n", n++);
>
>
> return 0;
> }


C:\tmp>lin foo.c

C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) foo.c
PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006

--- Module: foo.c (C)

C:\tmp>type _LINT.TMP | more

--- Module: foo.c (C)
_
printf("%d %d\n", n++, n);
foo.c( : Warning 564: variable 'n' depends on order of evaluation

---
output placed in _LINT.TMP

C:\tmp>splint foo.c
Splint 3.1.1 --- 12 Mar 2007

foo.c: (in function main)
foo.c(8,24): Argument 2 modifies n, used by argument 3 (order of evaluation
of
actual parameters is undefined): printf("%d %d\n", n++, n)
Code has unspecified behavior. Order of evaluation of function parameters
or
subexpressions is not defined, so if a value is used and modified in
different places not separated by a sequence point constraining evaluation
order, then the result of the expression is unspecified. (Use -evalorder
to
inhibit warning)

Finished checking --- 1 code warning

C:\tmp>type foo.c
#include <stdio.h>
int main(void)
{
int n = 0;
/* Not a problem, function call is a sequence point: */
printf("%d\n", n++);
/* Problem here, order unspecified */
printf("%d %d\n", n++, n);
return 0;
}



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Dann Corbit
Guest
Posts: n/a
 
      03-28-2008
"Ioannis Vranos" <> wrote in message
news:fsho27$1o9d$...
> Ian Collins wrote:
>> Ioannis Vranos wrote:
>>> Eric Sosman wrote:
>>>> Ioannis Vranos wrote:
>>>>> AFAIK the following is implementation-defined behaviour, am I right?:
>>>>>
>>>>>
>>>>> #include <stdio.h>
>>>>>
>>>>>
>>>>> int main(void)
>>>>> {
>>>>> int n= 0;
>>>>>
>>>>> printf("%d\n", n++);
>>>>>
>>>>>
>>>>> return 0;
>>>>> }
>>>> Only by quibbles: the form of "successful termination"
>>>> returned to the host environment is implementation-defined,
>>>> the actual new-line representation written to stdout in
>>>> response to the '\n' is implementation-defined, and things
>>>> of that sort.
>>>>
>>>> What aspect do you believe is not Standard-defined?
>>>
>>> I am talking about the implementation-defined behaviour of the printf()
>>> call described at 2.12 of K&R2.
>>>

>> There's nothing wrong with your example, the one you cite is completely
>> different. If you had tried to use n again in the printf, you would hit
>> UB.

>
>
> So, printf("%d %d\n", x++, x++); invokes implementation-defined

so does:
printf("%d %d\n", x++, x);

> behaviour, while printf("%d\n", x++); doesn't invoke
> implementation-defined behaviour?


This one does not.



--
Posted via a free Usenet account from http://www.teranews.com

 
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
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
Strange mouse behaviour with flash in Mozilla 1.3.7 hpoppe Firefox 0 11-07-2004 12:16 PM
Strange taskbar behaviour (notification area) Falcon Wireless Networking 0 08-17-2004 09:03 AM
[mozilla1.6] strange behaviour with newsgroup joost68 Firefox 5 04-03-2004 03:48 AM
A curious behaviour with an URL on the W3C Griffure Firefox 0 08-11-2003 11:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57