Re: what is happening in C when increment this way?
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 01/30/05
- Next message: CBFalconer: "Re: what is happening in C when increment this way?"
- Previous message: CBFalconer: "Re: Calling subroutine in fortran module"
- In reply to: puzzlecracker: "what is happening in C when increment this way?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 Jan 2005 15:09:39 GMT
puzzlecracker wrote:
>
> If you run this program, it will give very unexpected results. Can
> anyone explain the nature of this anamaly? (also what is the function
> call [and library to include linux/windows] to execute 'pause');
>
> #include<stdio.h>
>
> //void pause(){ unsigned long i=0; while(i++<10000000); }
>
> int main(){
> float i;
>
> for(i=0;i<100;i+=0.1) // pay attention
> { // pause();
> printf("%d\n",i);
> }
>
> printf("\n");
> return 0;
>
> }
Don't use C99 comments in C90 code. The result:
[1] c:\c\junk>gcc junk.c
junk.c:3: parse error before '/' token
junk.c: In function `main':
junk.c:8: parse error before '/' token
junk.c:10: warning: int format, double arg (arg 2)
junk.c: At top level:
junk.c:12: parse error before string constant
junk.c:12: warning: type defaults to `int' in declaration of
`printf'
junk.c:12: warning: conflicting types for built-in function
`printf'
junk.c:12: ISO C forbids data definition with no type or storage
class
After removing those execrences we get:
[1] c:\c\junk>gcc junk.c
junk.c: In function `main':
junk.c:8: warning: int format, double arg (arg 2)
and lying to the compiler about the type of an argument to a
variadic function is undefined behaviour.
There is no "pause" function in standard C.
-- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
- Next message: CBFalconer: "Re: what is happening in C when increment this way?"
- Previous message: CBFalconer: "Re: Calling subroutine in fortran module"
- In reply to: puzzlecracker: "what is happening in C when increment this way?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|