Re: [C] strange bug in code
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 05/07/04
- Next message: Francis Glassborow: "Re: [C] strange bug in code"
- Previous message: Francis Glassborow: "Re: Overload function"
- In reply to: Elliot Marks: "[C] strange bug in code"
- Next in thread: Robert B. Clark: "Re: [C] strange bug in code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 7 May 2004 15:45:27 +0100
In message <409B9BB3.1070700@email.net>, Elliot Marks <emarks@email.net>
writes
>I was wrestling with a stubborn bug in a C programming exercise. The
>correct program output was a string of ASCII codes that might look
>something like this:
>
> 50574852
>
>The corrupted output would look something like this:
>
> 5&@0&@5&@7&@...
>
>The function that generated the string had this header:
>
> char* ascii2str(char *digits, int ndigits)
>
>Changing the position of the asterisk operator in the first argument
>from char *digits to char* digits corrected the problem! Does this make
>sense to anybody? Is there a difference in the way the compiler
>distinguishes this:
>
> char* digits
>
>from this:
>
> char * digits
>
>from this:
>
> char *digits
>
>in the context of a function header (or any other context)?
Absolutely not, the placing of the whitespace is irrelevant you can even
write:
char*digits;
I suspect the problem is undefined behaviour somewhere in your
implementation of ascii2str()
>
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: Francis Glassborow: "Re: [C] strange bug in code"
- Previous message: Francis Glassborow: "Re: Overload function"
- In reply to: Elliot Marks: "[C] strange bug in code"
- Next in thread: Robert B. Clark: "Re: [C] strange bug in code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|