comp.lang.c
[Top] [All Lists]

Re: Implementation-defined behaviour

Subject: Re: Implementation-defined behaviour
From: "Dann Corbit"
Date: Thu, 27 Mar 2008 20:19:35 -0700
Newsgroups: comp.lang.c

"Ioannis Vranos" <ivranos@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message 
news:fshjmg$1avp$1@xxxxxxxxxxxxxxxxxxxxxx
> 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(8) : 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


<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy