Topic: type "long long" and array[0] decl.


Author: Tan&Marko <mmthm@bellsouth.net>
Date: 2000/01/29
Raw View
1) Is it legal C or C++ to declare a zero sized array as a struct
member?  This is a similar question to one recently asked, but the other
case was constructing a zero sized array in a new expression.  I don't
think it is legal, but could anyone confirm this?

struct {
    unsigned header;
    char data[0];
} packet;


2) Is there a basic type "long long" defined in either the C or C++
standard?  I have seen it used to declare 64bit ints.  If a given
architecture has historically used type "long" for 32 bit ints, what
type would be used to for 64bit ints?  Is there a standard rule, or even
a general rule as to what a compiler vendor should do?

3) Are the latest C++ standards docs available anywhere for free?

Thanks for your help.

Marko.
..


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/01/29
Raw View
Tan&Marko wrote:
>
> 1) Is it legal C or C++ to declare a zero sized array as a struct
> member?  This is a similar question to one recently asked, but the other
> case was constructing a zero sized array in a new expression.  I don't
> think it is legal, but could anyone confirm this?
>
> struct {
>     unsigned header;
>     char data[0];
> } packet;

In C99, you can get the desired affect using "char data[];". In C++,
neither syntax is legal, but many compilers allow the syntax you show as
an extension. Don't try it in non-POD structs, however.

> 2) Is there a basic type "long long" defined in either the C or C++
> standard?  I have seen it used to declare 64bit ints.  If a given
> architecture has historically used type "long" for 32 bit ints, what
> type would be used to for 64bit ints?  Is there a standard rule, or even
> a general rule as to what a compiler vendor should do?

In C99, "long long" is a new type, guaranteed to be at least 64 bits
long. However, if you need an exactly 64 bit integer, you must #include
<stdint.h>, and test whether INT64_MAX is #defined. If it isn't, there
is no exactly 64 bit integer type. If it is #defined, you can use
int64_t. int_least64_t is guaranteed to be available, and is the
smallest integer type with at least 64 bits; 'long long' might refer to
a wider type. intmax_t is the longest integer type, which therefore must
be at least 64 bits, but could be an implementation-specific type wider
than 'long long'.

int64_t(opt.) == 64 bits <= int_least64_t <= long long <= intmax_t

Each of the <stdint.h> types comes with a corresponding unsigned type
with the same name prefixed with "u", such as uint64_t.

C++ doesn't officially have 'long long'. However, many implementors are
likely to provide it as an extension. You'll also probably find
<stdint.h> available as an extension; it's one of the easiest parts of
C99 to add to C++.

> 3) Are the latest C++ standards docs available anywhere for free?

The standards organizations support themselves by selling the
documentation. The standards were developed by volunteers who actually
pay membership fees and for their own transportation to and from the
meetings (except for those lucky enough to get their companies to pay),
for the privelege of being allowed to work on the standard. In the US,
the C++ standard is available in PDF format for only $18 (follow the
links at the bottom of this message for details). For just about anyone
currently gainfully employed writing C++ code, that should be a
negligible amount. Pay up! Consider it your contribution to the effort.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Matt Austern <austern@sgi.com>
Date: 2000/01/30
Raw View
Tan&Marko <mmthm@bellsouth.net> writes:

> 2) Is there a basic type "long long" defined in either the C or C++
> standard?  I have seen it used to declare 64bit ints.  If a given
> architecture has historically used type "long" for 32 bit ints, what
> type would be used to for 64bit ints?  Is there a standard rule, or even
> a general rule as to what a compiler vendor should do?

No in C89, yes in C99, no in C++98.  It's a common extension, though
in C89 and C++98 compilers, though.

Vendors who define long to be a 32-bit type, and who also support a
64-bit type, have several options.  In C99 one obvious choice is to
define long long to be 64 bits.  In C89 or C++ it has to be some
nonstandard extension.  Usually it's either 'long long' or some
private builtin type, or both.  The IRIX compiler, for example,
defines an integer type called __int64_t.  (Double underscores for
reasons of standard conformance.  It's a reserved name, so it can't
collide with any legitimate user name.)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Tan&Marko <mmthm@bellsouth.net>
Date: 2000/01/30
Raw View

James Kuyper wrote:

> Tan&Marko wrote:
> >
> > 1) Is it legal C or C++ to declare a zero sized array as a struct
> > member?  This is a similar question to one recently asked, but the other
> > case was constructing a zero sized array in a new expression.  I don't
> > think it is legal, but could anyone confirm this?
> >
> > struct {
> >     unsigned header;
> >     char data[0];
> > } packet;
>
> In C99, you can get the desired affect using "char data[];". In C++,
> neither syntax is legal, but many compilers allow the syntax you show as
> an extension. Don't try it in non-POD structs, however.
>

What is a POD struct?

>
> > 2) Is there a basic type "long long" defined in either the C or C++
> > standard?  I have seen it used to declare 64bit ints.  If a given
> > architecture has historically used type "long" for 32 bit ints, what
> > type would be used to for 64bit ints?  Is there a standard rule, or even
> > a general rule as to what a compiler vendor should do?
>
> In C99, "long long" is a new type, guaranteed to be at least 64 bits
> long. However, if you need an exactly 64 bit integer, you must #include
> <stdint.h>, and test whether INT64_MAX is #defined. If it isn't, there
> is no exactly 64 bit integer type. If it is #defined, you can use
> int64_t. int_least64_t is guaranteed to be available, and is the
> smallest integer type with at least 64 bits; 'long long' might refer to
> a wider type. intmax_t is the longest integer type, which therefore must
> be at least 64 bits, but could be an implementation-specific type wider
> than 'long long'.
>
> int64_t(opt.) == 64 bits <= int_least64_t <= long long <= intmax_t
>
> Each of the <stdint.h> types comes with a corresponding unsigned type
> with the same name prefixed with "u", such as uint64_t.
>
> C++ doesn't officially have 'long long'. However, many implementors are
> likely to provide it as an extension. You'll also probably find
> <stdint.h> available as an extension; it's one of the easiest parts of
> C99 to add to C++.

Wow.  How would a "long long" literal (or any of these other new types) be
specified?

> > 3) Are the latest C++ standards docs available anywhere for free?
>
> The standards organizations support themselves by selling the
> documentation. The standards were developed by volunteers who actually
> pay membership fees and for their own transportation to and from the
> meetings (except for those lucky enough to get their companies to pay),
> for the privelege of being allowed to work on the standard. In the US,
> the C++ standard is available in PDF format for only $18 (follow the
> links at the bottom of this message for details). For just about anyone
> currently gainfully employed writing C++ code, that should be a
> negligible amount. Pay up! Consider it your contribution to the effort.
>
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

You are absolutely correct.  I will fork over the dough.
Do you know where one can get a copy of the C99 standard doc and how much it
costs?

Thank you James.

Marko.
..

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/01/30
Raw View
In article <3892451A.4488D716@bellsouth.net>, Tan&Marko
<mmthm@bellsouth.net> writes
>2) Is there a basic type "long long" defined in either the C or C++
>standard?  I have seen it used to declare 64bit ints.  If a given
>architecture has historically used type "long" for 32 bit ints, what
>type would be used to for 64bit ints?  Is there a standard rule, or even
>a general rule as to what a compiler vendor should do?

Over the 'dead bodies' of several experts C99 provides types long long
int  and unsigned long long int.  C++ does not (yet) support this
fundamental type.

>
>3) Are the latest C++ standards docs available anywhere for free?

Yes, but only to those of us who did the work.  Don't you think that is
fair?


Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/01/30
Raw View
Tan&Marko wrote:
....
> What is a POD struct?

This has come up freqently in this newsgroup; the most recent time was
only a month or so ago. Do a DejaNews search looking for "POD" in the
title.

....
> > In C99, "long long" is a new type, guaranteed to be at least 64 bits
> > long. However, if you need an exactly 64 bit integer, you must #include
> > <stdint.h>, and test whether INT64_MAX is #defined. If it isn't, there
> > is no exactly 64 bit integer type. If it is #defined, you can use
> > int64_t. int_least64_t is guaranteed to be available, and is the
> > smallest integer type with at least 64 bits; 'long long' might refer to
> > a wider type. intmax_t is the longest integer type, which therefore must
> > be at least 64 bits, but could be an implementation-specific type wider
> > than 'long long'.
> >
> > int64_t(opt.) == 64 bits <= int_least64_t <= long long <= intmax_t
> >
> > Each of the <stdint.h> types comes with a corresponding unsigned type
> > with the same name prefixed with "u", such as uint64_t.
> >
> > C++ doesn't officially have 'long long'. However, many implementors are
> > likely to provide it as an extension. You'll also probably find
> > <stdint.h> available as an extension; it's one of the easiest parts of
> > C99 to add to C++.
>
> Wow.  How would a "long long" literal (or any of these other new types) be
> specified?

A suffix of 'll' or 'LL' on an integer constant makes it 'long long'.
This can be combined in any order with 'u' or 'U' to make it 'unsigned
long long'. You can create an integer constant of type int_least64_t by
using the INT64_C() macro, and of type uint_least64_t by using the
UINT64_C() macro. INTMAX_C() creates a constant of type intmax_t. For
reasons that I don't remember, but would probably be blindingly obvious
if I thought about it long enough, conversion macros are provided for
the int_leastN_t types, but not for intN_t nor for int_fastN_t.

I'd recommend that replies concerning 'long long' go to comp.std.c,
rather than comp.std.c++. For the foreseeable future, it will be
available in C++ only as an extension.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]