Why?

Discussion in 'C Programming' started by maths_fan, Oct 18, 2003.

  1. maths_fan

    maths_fan Guest

    main()
    {
    int i = 7;
    double j = 8;
    printf("%x %x", i, j);
    }

    Quastion: maybe someone knows the way how printf works? I mean, I want
    to understand in detailes what it does when you want to print such
    type as double, using %x. By the way, does anyone have the source code
    of stdio.h (I mean, not stdio.h inself, but the functions written
    themselves, sorry for stupid quiastion.)
     
    maths_fan, Oct 18, 2003
    #1
    1. Advertising

  2. maths_fan

    Jack Klein Guest

    On 18 Oct 2003 09:18:13 -0700, (maths_fan) wrote in
    comp.lang.c:

    Why what?

    > main()


    The current C standard has outlawed implicit int. To make this legal
    C, if needs to be:

    int main()

    ....and even better is:

    int main(void)

    > {
    > int i = 7;
    > double j = 8;
    > printf("%x %x", i, j);


    This is undefined behavior, because the argument you pass to printf()
    does not match the conversion specifier. "%x" requires a parameter of
    type unsigned int, not double.

    > }
    >
    > Quastion: maybe someone knows the way how printf works? I mean, I want
    > to understand in detailes what it does when you want to print such
    > type as double, using %x. By the way, does anyone have the source code
    > of stdio.h (I mean, not stdio.h inself, but the functions written
    > themselves, sorry for stupid quiastion.)


    There are quite a few open-source compilers to be found on the
    Internet, including source code for their library functions.

    http://gcc.gnu.org/ for one.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Oct 18, 2003
    #2
    1. Advertising

  3. (maths_fan) writes:
    > main()
    > {
    > int i = 7;
    > double j = 8;
    > printf("%x %x", i, j);
    > }
    >
    > Quastion: maybe someone knows the way how printf works? I mean, I want
    > to understand in detailes what it does when you want to print such
    > type as double, using %x. By the way, does anyone have the source code
    > of stdio.h (I mean, not stdio.h inself, but the functions written
    > themselves, sorry for stupid quiastion.)


    There is no such thing as "the" source code of stdio.h. There are a
    number of implementations, most of which will work only in the
    environment for which they were designed.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Oct 18, 2003
    #3
  4. maths_fan

    Dan Pop Guest

    In <> (maths_fan) writes:

    >main()
    >{
    > int i = 7;
    > double j = 8;
    > printf("%x %x", i, j);
    >}
    >
    >Quastion: maybe someone knows the way how printf works? I mean, I want
    >to understand in detailes what it does when you want to print such
    >type as double, using %x.


    How about learning C, instead of wasting your time with pieces of broken
    C code?

    Your code contains no less than three major errors:

    1. Calling printf without a valid prototype in scope.

    2. Passing an int value to %x.

    3. Passing a double value to %x.

    >By the way, does anyone have the source code
    >of stdio.h (I mean, not stdio.h inself, but the functions written
    >themselves, sorry for stupid quiastion.)


    At your current level, you need not worry about such things. Much better
    to focus your attention on learning C. Once K&R2 has no secrets for you,
    you can start studying Plauger's "The Standard C Library" which contains
    an (almost) complete implementation of its title.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 20, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    580
    Juan T. Llibre
    Jan 27, 2005
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    470
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    VWD why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    =?Utf-8?B?Q2lhcmFuIE8nJycnRG9ubmVsbA==?=
    Dec 21, 2006
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    921
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,072
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page