size_t

J

josh

Hi,

I want to find the #DEFINE of size_t but in <stddef.h> I don't see
it...

I'm using gcc 4.1.2 on Linux

Thanks
 
N

Neelesh Bodas

Hi,

I want to find the #DEFINE of size_t but in <stddef.h> I don't see
it...

IIRR, size_t is not a macro but a typedef. The exact type is not
specified by the standard. One of the many usages of size_t is to
denote the type of value returned by sizeof().

With GCC , you might find find something similar to typedef
__SIZE_TYPE__ size_t, but thats compiler dependent.

-Neelesh
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi,

I want to find the #DEFINE of size_t but in <stddef.h> I don't see
it...

Why, just include <stddef.h> or <cstddef> and you have have it. Remember
that the size of size_t can vary between different hardware so typing
code that depends on size_t being of a specific size is stupid.
 
J

josh

IIRR, size_t is not a macro but a typedef. The exact type is not
specified by the standard. One of the many usages of size_t is to
denote the type of value returned by sizeof().

With GCC , you might find find something similar to typedef
__SIZE_TYPE__ size_t, but thats compiler dependent.

-Neelesh

Yes but I have been confused by this:

in stddef.h

#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t;

now why is **defined** __SIZE_TYPE__ and not simple
typedef long unsigned int __SIZE_TYPE__

and when is written >> defined (size_t)) where is size_t before type-
defined?

and also how is used typedef???
when compiler meets >> typedef __SIZE_TYPE__ size_t;
it should convert __SIZE_TYPE__ in long unsigned int accordingly with
previous #define __SIZE_TYPE__ long unsigned int but typedef don't
want
like its first operand the type synonymous and like second operand the
real type??

Oh, I'm very confused!!
 
N

Neelesh Bodas

Yes but I have been confused by this:

in stddef.h

#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t;

now why is **defined** __SIZE_TYPE__ and not simple
typedef long unsigned int __SIZE_TYPE__


this is probably very specific to the GCC handles C++ libraries. That
has nothing to do with C++ standard.
and when is written >> defined (size_t)) where is size_t before type-
defined?

Specific to GCC.
and also how is used typedef???
when compiler meets >> typedef __SIZE_TYPE__ size_t;
it should convert __SIZE_TYPE__ in long unsigned int accordingly with
previous #define __SIZE_TYPE__ long unsigned int but typedef don't
want
like its first operand the type synonymous and like second operand the
real type??

syntax for typedef is : typedef old_type new_type;
more on typedef here:
Oh, I'm very confused!!


Note that if you are digging up in the headers just for the sake of
getting an understanding specific to GCC, then its fine. But if you
plan to use this information while writing (portable) C++ code, you
will end up in trouble.

-Neelesh
 
J

James Kanze

But is required to be an unsigned integral type. (According to
the current C++ standard, it must be a standard unsigned
integral type; i.e. one of "unsigned char", "unsigned short",
"unsigned int" or "unsigned long". C99 and I believe the next
version of the C++ standard will allow an extended integral
types as well, e.g. uint64_t, where even long is only 32 bits.)
Yes but I have been confused by this:

By snooping where you have no business snooping:).
in stddef.h
#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t;
now why is **defined** __SIZE_TYPE__ and not simple
typedef long unsigned int __SIZE_TYPE__

Because that's the way the authors of this particular library
wanted to do it. (I suspect that it has something to do with
the way they handle system dependencies.) At any rate, anything
with a double underscore is of no concern to you, unless the
compiler documentation explicitly says otherwise. (Some---I
think even many---compilers use macros with double underscores
to turn features on or off. That's obviously not the case
here.)
and when is written >> defined (size_t)) where is size_t before type-
defined?

Again, it's something internal to the implementation.
"defined( size_t )" will only evaluate to true if size_t is
already defined as a macro. Which isn't allowed: the
implementation isn't allowed to define size_t as a macro, and if
you define it as one, it is undefined behavior. Apparently,
your library "defines" the undefined behavior, as an extension.
I can't imagine a case where it would be useful,
however---perhaps when compiling some special kernel code?
Don't do it, unless you really, really know what you are doing.
and also how is used typedef???

Typedef defines a symbol which is the name of the type. You
write the declaration exactly like any other declaration, but
the name being defined is not a variable, but the name of a
type, which can be used as the name of a type whenever it is in
scope. E.g.:

int array[ 10 ] ; // defines an array of 10 ints,
// a variable.

typedef int Array10[ 10 ] ; // defines a symbol Array10,
// which can be used as the
// name of a type.
Array10 array2 ; // defines an array of 10 ints,
// a variable.

when compiler meets >> typedef __SIZE_TYPE__ size_t;
it should convert __SIZE_TYPE__ in long unsigned int accordingly with
previous #define __SIZE_TYPE__ long unsigned int but typedef don't
want
like its first operand the type synonymous and like second operand the
real type??

I'm having difficulty parsing that last phrase. After macro
expansion, yes, you have:

typedef long unsigned int size_t ;

If size_t is already defined in the scope, it is an error.
Otherwise, it defines a new symbol, size_t, as a synonym for the
type long unsigned ing.
 
J

josh

But is required to be an unsigned integral type. (According to
the current C++ standard, it must be a standard unsigned
integral type; i.e. one of "unsigned char", "unsigned short",
"unsigned int" or "unsigned long". C99 and I believe the next
version of the C++ standard will allow an extended integral
types as well, e.g. uint64_t, where even long is only 32 bits.)


By snooping where you have no business snooping:).


Because that's the way the authors of this particular library
wanted to do it. (I suspect that it has something to do with
the way they handle system dependencies.) At any rate, anything
with a double underscore is of no concern to you, unless the
compiler documentation explicitly says otherwise. (Some---I
think even many---compilers use macros with double underscores
to turn features on or off. That's obviously not the case
here.)

so that #define __SIZE_TYPE__ long unsigned int is out of standard or
normal use
and it's a mystery why this contextual use!
however if I try to:

#define ANY unsigned int
typedef ANY any_any;

I have the following error:
declaration does not declare anything

I'm using gcc 4 and why here the compiler give me an error and
don't give me the same error when including that header???

Regards
 
J

James Kanze

On 3 Lug, 09:43, James Kanze <[email protected]> wrote:

[...]
so that #define __SIZE_TYPE__ long unsigned int is out of
standard or normal use and it's a mystery why this contextual
use!
Quite.

however if I try to:
#define ANY unsigned int
typedef ANY any_any;
I have the following error:
declaration does not declare anything

Really. I don't. It's perfectly legal according to the
standard, and works with the compilers I have on this machine
(Sun CC and g++).
I'm using gcc 4 and why here the compiler give me an error and
don't give me the same error when including that header???

You've mistyped something. The above works with g++ 4.1.0. (I
get the "declaration does not declare anything" error if I put
a ';' between the unsigned and the int in the #define. But
that's to be expected.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top