Re: printf doubt
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 13 Jul 2006 22:05:16 GMT
Joe Wright <joewwright@xxxxxxxxxxx> writes:
Ben Pfaff wrote:
Barry Schwarz <schwarzb@xxxxxxxxx> writes:
On Tue, 11 Jul 2006 10:09:17 -0700, Ben Pfaff <blp@xxxxxxxxxxxxxxx>What systems use separate stacks for return addresses and
wrote:
Barry Schwarz <schwarzb@xxxxxxxxx> writes:I wonder how systems which push return addresses and arguments on the
Does not the presence of a superfluous argument lead to undefinedNo. From C99 7.19.6.1 "The fprintf function":
behavior?
If the format is exhausted while arguments remain, the
excess arguments are evaluated (as always) but are otherwise
ignored.
same stack, like the old 6502, manage this.
arguments? I am not aware of any in the modern world, so it
would be educational to hear about them. Such a system might be
more resistant to "stack smashing" buffer overflow attacks, for
one thing.
Obviously, fprintf will not pop the superfluous arguments offA common convention is for the callee to pop off the return
the stack since it doesn't even know about them.
address and leave the arguments on the stack. The caller then
pops the arguments.
Missing the point maybe. There are some number of arguments to printf,
one of them being the format string. Let's assume a format string and
four other expressions. That's five arguments. If the format string
describes what to do with only two expressions, so be it. Only two
will be treated. But five arguments were pushed and five will be
popped.
Which means that a calling convention where the callee needs to know
how many arguments were passed won't work for printf() or other
variadic functions (unless there's an extra implicit argument that
provides that information).
A C compiler *could* use such a convention for non-variadic functions,
but I think most compilers use the same convention for both (since
there was no such distinction in early C).
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: printf doubt
- From: Flash Gordon
- Re: printf doubt
- References:
- printf doubt
- From: dutche
- Re: printf doubt
- From: Richard Heathfield
- Re: printf doubt
- From: Barry Schwarz
- Re: printf doubt
- From: Ben Pfaff
- Re: printf doubt
- From: Barry Schwarz
- Re: printf doubt
- From: Ben Pfaff
- Re: printf doubt
- From: Joe Wright
- printf doubt
- Prev by Date: Re: C is too old? opinions?
- Next by Date: Re: What is strcmp supposed to return if one or both arguments passed to it are NULL ?
- Previous by thread: Re: printf doubt
- Next by thread: Re: printf doubt
- Index(es):
Relevant Pages
|