Re: low-level question
- From: gordonb.pxva5@xxxxxxxxxxx (Gordon Burditt)
- Date: Tue, 30 Aug 2005 13:02:13 -0000
>I couldn't get this on a midterm. Darn!
>
>Anyone want to help?
>
>1. Why does the following program output a 0?
Who says it does? The standard certainly doesn't require it.
>2. Explain in detail.
There are no guarantees that if you overflow an array, it will overflow
into the variable declared immediately after it. (On some linkers,
it will overflow into the variable *alphabetically* after it, given
that they're both auto variables in the same function.) There are also
no guarantees that this code is running on an endian machine.
>3. How could you prevent this outcome without changing the code?
Don't run it? Run on a non-endian machine? Kill the author
of the code?
>
>
>#include <stdio.h>
>#include <string.h>
>
>int
>main( int argc, char *argv[] )
>{
> int ii = 1;
> char buf[ 4 ];
>
> strcpy( buf, "AAAA" );
>
> printf( "%d\n", ii );
>
> return 0;
>}
>
.
- Follow-Ups:
- Re: low-level question
- From: jesso
- Re: low-level question
- References:
- low-level question
- From: jesso
- low-level question
- Prev by Date: Re: How to free dynamically allocated array?
- Next by Date: Re: understanding format specifiers
- Previous by thread: Re: low-level question
- Next by thread: Re: low-level question
- Index(es):
Relevant Pages
|