By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

%lld conversion

P: n/a
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.

--
nethlek
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 7 Dec 2003 21:57:53 -0800, co****@lawyer.com (conrad) wrote in
comp.lang.c:
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
Nov 13 '05 #2

P: n/a
In <t7********************************@4ax.com> Jack Klein <ja*******@spamcop.net> writes:
On 7 Dec 2003 21:57:53 -0800, co****@lawyer.com (conrad) wrote in
comp.lang.c:
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.

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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.