is this a FBSD printf bug?

abc_at_ai1.anchorage.mtaonline.net
Date: 06/21/03

  • Next message: Matthew Seaman: "Re: is this a FBSD printf bug?"
    Date: Sat, 21 Jun 2003 10:14:12 GMT
    To: "freebsd-questions" <questions@freebsd.org>
    
    

    FBSD 4.8

    i hope this isn't a question based on extreme
    ignorance - i haven't programmed in C in a
    long time, and i don't have another machine
    to test this on. i can't understand why
    the output of the following code produces
    "ints" when given variables of type "char",
    so it looks like a bug to me ...

    #include <stdio.h>
    ///////////////////////////////////////////////////////////////////////////////
    int main(int argc, char *argv[]) {

    #define LEN_ARRAY 16
    char a[LEN_ARRAY+1];
    int i;

    a[0]=0x00;
    a[1]=0x11;
    a[2]=0x22;
    a[3]=0x33;
    a[4]=0x44;
    a[5]=0x55;
    a[6]=0x66;
    a[7]=0x77;
    a[8]=0x88;
    a[9]=0x99;
    a[10]=0xaa;
    a[11]=0xbb;
    a[12]=0xcc;
    a[13]=0xdd;
    a[14]=0xee;
    a[15]=0xff;

        for ( i = 0; i < LEN_ARRAY; ++i ) printf("[%02i]%02x\n", i, a[i]);
    }
    ///////////////////////////////////////////////////////////////////////////////
    //
    // OUTPUT:
    //
    // [00]00
    // [01]11
    // [02]22
    // [03]33
    // [04]44
    // [05]55
    // [06]66
    // [07]77
    // [08]ffffff88 ???
    // [09]ffffff99 ???
    // [10]ffffffaa ???
    // [11]ffffffbb ???
    // [12]ffffffcc ???
    // [13]ffffffdd ???
    // [14]ffffffee ???
    // [15]ffffffff ???
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: Matthew Seaman: "Re: is this a FBSD printf bug?"

    Relevant Pages

    • Re: is this a FBSD printf bug?
      ... > i hope this isn't a question based on extreme ... > ignorance - i haven't programmed in C in a ... case 'char' is promoted to 'int'. ... The reason the results you're ...
      (freebsd-questions)
    • Re: CreateProcess in a loop
      ... and I'm more extreme than a lot of MFC example code. ... programmer would write. ... At one time char was important and represented state-of-the-art, ... Books I have are introduction to MFC which is not ...
      (microsoft.public.vc.mfc)
    • Re: Natural size: int
      ... A char should be the smallest addressable unit of memory; ... system only supports 16-bit loads, ... You assume that shorter ints are somehow more efficient than longer ...
      (comp.lang.c)
    • Re: code review please
      ... On Wed, 11 Aug 2004, Marlene Stebbins wrote: ... > Rabin-Miller algorithm. ... Read Section 14 of the C FAQ for why ints and floats don't mix. ... void do_error(const char *fmat, ...); ...
      (comp.programming)
    • Re: Binary file from C++ to Matlab
      ... 8-bit chars, 16-bit ints, or 32-bit ints and so on. ... You can read a binary file without knowing the exact size of an ... If you e.g. know that a char is at least 8 bits, ... achieved using bitfields. ...
      (comp.soft-sys.matlab)