From: A. McKenney on
On Apr 27, 9:53 am, �� Tiib <oot...(a)hot.ee> wrote:
> On Apr 27, 3:10 am, "A. McKenney" <alan_mckenn...(a)yahoo.com> wrote:

> size_t is yes synonym for implementation defined unsigned integral
> type, so it should work. However i believe that a program is ill-
> formed if you use identifier size_t without including <cstddef> that
> introduces that name. Problem may be is there since your code example
> does not show that you include it.

I do not. This snippet had no #include's at all.

I tried including <cstddef>, but that is not enough: you need
a using declaration, too:

#include <cstddef>
using std::size_t;

I believe you, that it's required by the standard,
but it's not a very well-publicized fact.

I have been programming in C++ for over 10 years,
and this is the first time I have ever heard this
or ever had to worry about defining size_t.
I had assumed that size_t was a new built-in type, the
way I've seen it used in the standard texts.

If it is mentioned in Josuttis or Stroustrup
that you need <cstddef>, I missed it.

I can only assume that all the C++ headers and
quite a few C headers on all the implementations
I use already define size_t, and this was
the first time I hadn't included one.

FWIW, a quick cruise through /usr/include on
Solaris shows size_t being typedef'ed in
quite a few files.
Same for the various flavors of C++ headers.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 28 Apr., 00:20, "A. McKenney" <alan_mckenn...(a)yahoo.com> wrote:
> On Apr 27, 9:53 am, �� Tiib <oot...(a)hot.ee> wrote:
>
> > On Apr 27, 3:10 am, "A. McKenney" <alan_mckenn...(a)yahoo.com> wrote:
> > size_t is yes synonym for implementation defined unsigned integral
> > type, so it should work. However i believe that a program is ill-
> > formed if you use identifier size_t without including <cstddef> that
> > introduces that name. Problem may be is there since your code example
> > does not show that you include it.
>
> I do not. This snippet had no #include's at all.
>
> I tried including <cstddef>, but that is not enough: you need
> a using declaration, too:
>
> #include <cstddef>
> using std::size_t;

Why should you do that? Either include <stddef.h> and
use size_t or include <cstddef> and use std::size_t.

> I believe you, that it's required by the standard,
> but it's not a very well-publicized fact.
>
> I have been programming in C++ for over 10 years,
> and this is the first time I have ever heard this
> or ever had to worry about defining size_t.
> I had assumed that size_t was a new built-in type, the
> way I've seen it used in the standard texts.

If you explicitly name size_t you need to include
<stddef.h> or some of the other dedicated includes
that promise so, like <stdio.h>. Only implicit
usage is possible without such an include like

sizeof(char);

> If it is mentioned in Josuttis or Stroustrup
> that you need <cstddef>, I missed it.

The C standard already requires that, see 6.5.3.4/4:

"The value of the result is implementation-defined,
and its type (an unsigned integer type) is size_t,
defined in <stddef.h> (and other headers)."

or 7.17/2 (Both quotes from the recent C99 standard)

> I can only assume that all the C++ headers and
> quite a few C headers on all the implementations
> I use already define size_t, and this was
> the first time I hadn't included one.

Yes, this is rather probable.

HTH & Greetings from Bremen

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]