Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
Kenji
on June 1, 2014
|
parent
|
context
|
favorite
| on:
Write a program that makes 2 + 2 = 5
It's only likely, but not certain that a or b get overwritten. How your stack is laid out is entirely up to the compiler. arr[1] is already out of bounds, however, we don't know for certain what's immediately above the array.
codeflo
on June 1, 2014
[–]
With compiler optimizations turned on, it's almost guaranteed
not
to happen, because a and b are very likely to be stored in CPU registers.
mgraczyk
on June 1, 2014
|
parent
[–]
Or rather, a and b will be constant folded so that the printf call is optimized to "push #4; push ptrFmt; call printf"
Someone
on June 1, 2014
|
root
|
parent
[–]
A truly good compiler would replace that printf by a call to putchar or pass a constant string to 'write' (gcc almost (?) does that. See
http://www.ciselant.de/projects/gcc_printf/gcc_printf.html
)
Consider applying for YC's Spring batch! Applications are open till Feb 11.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: