Why?

M

maths_fan

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.)
 
J

Jack Klein

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

Why what?

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
 
K

Keith Thompson

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.
 
D

Dan Pop

In said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top