%lld conversion

C

conrad

for something like printf("%lld\n", 1);
what section in the standard describes what type the argument "1"
is promoted to?

All I see is a section describing promotion from
float to double but nothing else.
 
J

Jack Klein

for something like printf("%lld\n", 1);
what section in the standard describes what type the argument "1"
is promoted to?

All I see is a section describing promotion from
float to double but nothing else.

There is no promotion of the of the argument. The numeric literal "1"
has the type signed int, and it is passed as a signed int.

The promotion rules for the *printf() functions are the same as those
for any other variadic function. Any argument of a lesser rank than
int or signed int gets promoted to either signed or unsigned int. Any
argument of type float gets promoted to double. Any other argument
type is unchanged. The format string has absolutely no impact on the
conversion rules, although some compilers have an option to check them
for you.

So the printf() call you wrote has undefined behavior because it
passes a signed int with a conversion specifier of signed long long.

If you want to print the numeric literal '1' as a signed long long,
you need to write it as 1LL or (long long)1.

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

Dan Pop

The default argument promotions specify more than that.
So the printf() call you wrote has undefined behavior because it
passes a signed int with a conversion specifier of signed long long.

Or, depending on the implementation, because of the invalid %lld
conversion specifier.

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top