Re: Most Interesting Bug Track Down
- From: lawrence.jones@xxxxxxx
- Date: Tue, 28 Nov 2006 15:16:12 GMT
James Dow Allen <jdallen2000@xxxxxxxxx> wrote:
and another function
whatever( ..., short cmd);
which needed, among other things to send the 2-byte cmd
to the chip. Endianness was not an issue, as my program
was specific to MC680x0.
I tried to send the bytes with
send_to_chip(&cmd, 2);
but it didn't work. Eventually I found that "&cmd" was pointing
2 bytes *before* the 2-byte cmd on the stack.
That was a common behavior in pre-ANSI compilers. Since char and short
arguments are promoted to int (and float arguments are promoted to
double), many compilers just rewrote the argument declarations as the
widened type (much as array arguments declarations are rewritten as
pointer declarations). ANSI outlawed that practice, requiring the
arguments to have their explicitly declared type, not the widened type.
-Larry Jones
What better way to spend one's freedom than eating chocolate
cereal and watching cartoons! -- Calvin
.
- References:
- Most Interesting Bug Track Down
- From: Frederick Gotham
- Re: Most Interesting Bug Track Down
- From: Mark F. Haigh
- Re: Most Interesting Bug Track Down
- From: James Dow Allen
- Most Interesting Bug Track Down
- Prev by Date: Re: Sharing static variables or function between source files.
- Next by Date: Re: removing newline character from the buffer read by fgets
- Previous by thread: Re: Most Interesting Bug Track Down
- Next by thread: Re: Most Interesting Bug Track Down
- Index(es):