![]() |
Re: questions about constants
In message <nT5rc.2704$eH3.54819@news4.e.nsc.no>
Martin Johansen <mfag@online.no> wrote: > Hello > > I was not able to find answers to there Qs on google or in the FAQ, so > here goes > > Q1: > I refer to the question 2.10 in the FAQ > the following code compiled with gcc > (struct {int a; char* b; int c;}){1, "1", 'A'}.c > but is it valid ansi c? It's valid in ISO C99, but not earlier versions. > Q2: > Are these equivalent? > (long)1 contra 1L Yes, for that specific example, barring syntax quirks (eg "sizeof (long)1" will be parsed differently from "sizeof 1L"). This might not be: (long)1000000000000 vs 1000000000000L because the suffix only specifies a minimum size, and it will grow to long long if necessary. The first form would truncate it back down to long, even if it didn't fit. > Q3: > I know of the following "constant classifiers" i.e. 1L > l and L, f and F, u and U > but are there more? C99 has "ll" or "LL" for long long. -- Kevin Bracey, Principal Software Engineer Tematic Ltd Tel: +44 (0) 1223 503464 182-190 Newmarket Road Fax: +44 (0) 1728 727430 Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/ |
Re: questions about constants
Martin Johansen <mfag@online.no> writes:
> Q1: > I refer to the question 2.10 in the FAQ > the following code compiled with gcc > (struct {int a; char* b; int c;}){1, "1", 'A'}.c > but is it valid ansi c? This is called a compound literal; it is valid according to the current ISO C standard (C99). Note, however, that most compilers do not yet implement C99, but C89, the previous C standard. (GCC implements C99 only partially.) > Q2: > Are these equivalent? > (long)1 contra 1L Yes. > Q3: > I know of the following "constant classifiers" i.e. 1L > l and L, f and F, u and U > but are there more? For integers, there are the suffixes L (long), U (unsigned), and UL (unsigned long), and in C99 LL (long long) and ULL (unsigned long long). For floating-point numbers, there are F (float) and L (long double). All suffixes can be spelled in uppercase or lowercase letters. Martin -- ,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =. / ,- ) http://www.zero-based.org/ ((_/)o o(\_)) \ `-' `-'(. .)`-' `-. Debian, a variant of the GNU operating system. \_/ |
questions about constants
Hello
I was not able to find answers to there Qs on google or in the FAQ, so here goes Q1: I refer to the question 2.10 in the FAQ the following code compiled with gcc (struct {int a; char* b; int c;}){1, "1", 'A'}.c but is it valid ansi c? Q2: Are these equivalent? (long)1 contra 1L Q3: I know of the following "constant classifiers" i.e. 1L l and L, f and F, u and U but are there more? Thank you! |
| All times are GMT. The time now is 10:12 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.