Re: inside scanf [trap rep]
- From: "Clark S. Cox III" <clarkcox3@xxxxxxxxx>
- Date: Wed, 31 Jan 2007 08:33:06 -0500
temper3243@xxxxxxxxx wrote:
On Jan 31, 11:59 am, CBFalconer <cbfalco...@xxxxxxxxx> wrote:
temper3...@xxxxxxxxx wrote:Few more questions
Can someone explain me what is happening below ? Why is it printingWhy don't you give it an integer for input? Usual sin - failure to
401380
$ cat scanf.c
#include<stdio.h>
int main()
{
int i;
scanf(" %d",&i);
printf("%x\n",i);
return 0;
}
prog@cygwin ~
$ ./a.exe
-1
ffffffff
prog@cygwin ~
$ ./a.exe
--1
401380
check the return value from scanf.
1) Can a variable contain trap representation(trap rep) say a local
variable like int i;
Yes
2) Can a pointer contain trap rep ? like say int *p, can p be a trap
rep.
Yes
3) Can address of an uninitialized variable every contain trap rep ?
i.e can "&i" contain trap rep
No
4) Can we get to assign trap rep "on a 2's complement machine" ? i.e
int i= value_of_traprep;
No, as far as C is concerned, a variable containing a trap
representation doesn't have a value. Just attempting to do the above
initialization invokes undefined behavior.
printf(" %d",i); will it abort ;
5) On a 1's complement machine is trap rep always ~0 or is it
different.
There is no way a conforming program can know this.
When ~0 is trap rep,
what happens,
int i=~0,
printf(" %d",i); will it abort ;
6) How do i get what is the value for trap rep on my arch (i386) .
Not every platform has trap representations, you just have to be aware
that they *might*. Essentially, your questions come down to : "What
happens when I invoke undefined behavior?". The answer is: "anything or
nothing."
--
Clark S. Cox III
clarkcox3@xxxxxxxxx
.
- References:
- inside scanf
- From: temper3243
- Re: inside scanf
- From: CBFalconer
- Re: inside scanf [trap rep]
- From: temper3243
- inside scanf
- Prev by Date: Re: How to reduce Zero Initialised region.
- Next by Date: check if the memory is low, from Windows to Unix
- Previous by thread: Re: inside scanf [trap rep]
- Next by thread: Trap representation (was: inside scanf [trap rep])
- Index(es):
Relevant Pages
|