compare a large number of variables

C

Chris Torek

Even assuming both types are passed in the *same* register, the code
can fail if a null pointer isn't represented as all-bits-zero. There
may be other ways it can fail that I can't think of off the top of my
head.

The usual one is that you run out of argument registers, so that
remaining arguments are passed by some other mechanism, where the
size does matter. For instance, on MIPS, you get four "integer-like"
arguments via registers, the rest via temporary storage the compiler
allocates in an appropriate stack frame; on SPARC you get six; on
PowerPC the number depends on whose ABI you use, I believe.

Thus:

printf("%p", 0);

"just happens" to work, but:

printf("i: %d, s: %s, c: %c, p: %p", i, s, c, 0);

"just happens" to behave bizarrely on a 64-bit MIPS. (The four
arguments a0 through a3 include the format and i, s, and c; the
fifth argument for %p -- given incorrectly here as an unadorned
integer constant zero -- writes only 32 of the 64 bits that will
be read.)

The same code "just happens" to work on the SPARC until two more
parameters are inserted.
Yup. In fact, it invokes undefined behavior, with all that implies.

Indeed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top