questions about constants

Discussion in 'C Programming' started by Kevin Bracey, May 20, 2004.

  1. Kevin Bracey

    Kevin Bracey Guest

    In message <nT5rc.2704$>
    Martin Johansen <> 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/
    Kevin Bracey, May 20, 2004
    #1
    1. Advertising

  2. Martin Johansen <> 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. \_/
    Martin Dickopp, May 20, 2004
    #2
    1. Advertising

  3. 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!
    Martin Johansen, May 21, 2004
    #3
    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. SpOiLeR
    Replies:
    6
    Views:
    4,117
    Victor Bazarov
    Mar 15, 2005
  2. Ali Syed
    Replies:
    3
    Views:
    543
    Mark McIntyre
    Oct 13, 2004
  3. Leslie Sanford
    Replies:
    1
    Views:
    275
    James Kanze
    Aug 4, 2008
  4. Luca Forlizzi

    Questions on character constants

    Luca Forlizzi, Dec 12, 2010, in forum: C Programming
    Replies:
    2
    Views:
    326
    luser- -droog
    Dec 13, 2010
  5. Edward Rutherford

    Questions on ISO C character constants

    Edward Rutherford, Nov 8, 2011, in forum: C Programming
    Replies:
    1
    Views:
    333
    Kaz Kylheku
    Nov 8, 2011
Loading...

Share This Page