Re: [C] strange bug in code

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 05/07/04


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


Relevant Pages

  • Re: How to add thousand separators
    ... First, this code is obsolete as written, because char is a dead data type and should not ... Note that both of these should be stored as string resources since they might need to be ... 18 digits for any reason. ... you have made a VERY SERIOUS DESIGN ERROR. ...
    (microsoft.public.vc.mfc)
  • [C] strange bug in code
    ... The correct program output was a string of ASCII codes that might ... argument from char *digits to char* digits corrected the problem! ... in the context of a function header? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: HEXADECIMAL to STRING
    ... suppose that I have a string that is an hexadecimal number, ... void print_hex(unsigned char *bs, unsigned int n){ ... You have "len" digits. ...
    (comp.lang.c)
  • Re: How to convert extra long strings into their equivalent Hex Strings in VBA (Word 2K)
    ... numbers (upto 18 digits max) into its equivalent Hex String ... Public Function ExpressServiceCode(ByVal ServiceTag As String) As String ... 'the number dblTemp in the specified base, ... Dim lngTemp As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: BigNum -- Floating Point
    ... The 'N' is the number of decimal digits. ... The internal representation is really just a string of bits. ... the number of shifts for various multiples of ten: ... The 'exponent' is very closely related to ...
    (comp.programming)