[GRASS-dev] The "nature" of size_t

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned) parameter, even if in alloc.c I find that the first argument of G_calloc has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano

What? No it doesn't. How do you figure it expects a signed integer?

The definition of G_calloc doesn't have anything to do with how the
compiler thinks it is. Have you redefined G_calloc somewhere? If you
declare in your own file G_calloc(unsigned int, unsigned int); Then the
compiler will think that G_calloc expects two unsigned integers, no
matter how it is really in alloc.c, since the compiler will not look in
alloc.c when compiling your stuff.

--Wolf

On 27.03.2007 12:42, Damiano Triglione wrote:

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of G_calloc
has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

Thanks!
I presumed it expected a signed integer, because if I invoke it with an unisgned int parameter, I have a warning:
   warning: passing arg 1 of `G_calloc' as signed due to prototype

even if I did not redefine G_calloc anywhere.
Thus, do you think that if I declare in my file
   G_calloc(unsigned int, unsigned int);
I can then eliminate the warning, instead of using a cast in every invocation?

Damiano

----- Original Message ----- From: "Wolf Bergenheim" <wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 12:31 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

What? No it doesn't. How do you figure it expects a signed integer?

The definition of G_calloc doesn't have anything to do with how the
compiler thinks it is. Have you redefined G_calloc somewhere? If you
declare in your own file G_calloc(unsigned int, unsigned int); Then the
compiler will think that G_calloc expects two unsigned integers, no
matter how it is really in alloc.c, since the compiler will not look in
alloc.c when compiling your stuff.

--Wolf

On 27.03.2007 12:42, Damiano Triglione wrote:

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of G_calloc
has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

You probably haven't included <grass/gis.h> which defines a prototype
for G_calloc and friends. The compiler defaults the prototype to signed int.

So be sure you have a #include <grass/gis.h> in your file where you use
G_calloc, to get the prototype for G_calloc, and get rid of your error.

--Wolf

On 27.03.2007 14:07, Damiano Triglione wrote:

Thanks!
I presumed it expected a signed integer, because if I invoke it with an
unisgned int parameter, I have a warning:
  warning: passing arg 1 of `G_calloc' as signed due to prototype

even if I did not redefine G_calloc anywhere.
Thus, do you think that if I declare in my file
  G_calloc(unsigned int, unsigned int);
I can then eliminate the warning, instead of using a cast in every
invocation?

Damiano

----- Original Message ----- From: "Wolf Bergenheim"
<wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 12:31 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

What? No it doesn't. How do you figure it expects a signed integer?

The definition of G_calloc doesn't have anything to do with how the
compiler thinks it is. Have you redefined G_calloc somewhere? If you
declare in your own file G_calloc(unsigned int, unsigned int); Then the
compiler will think that G_calloc expects two unsigned integers, no
matter how it is really in alloc.c, since the compiler will not look in
alloc.c when compiling your stuff.

--Wolf

On 27.03.2007 12:42, Damiano Triglione wrote:

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of G_calloc
has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

To be honest, I included "gis.h" because I am still using Grass 6.0, so - if I am not wring - I should not use <grass/...>.
Maybe I have this kind of problem for this reason?
Do you think that in Grass 6.2.1 the prototype of G_calloc is different from the one in Grass 6.0?
Damiano

----- Original Message ----- From: "Wolf Bergenheim" <wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 1:32 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

You probably haven't included <grass/gis.h> which defines a prototype
for G_calloc and friends. The compiler defaults the prototype to signed int.

So be sure you have a #include <grass/gis.h> in your file where you use
G_calloc, to get the prototype for G_calloc, and get rid of your error.

--Wolf

On 27.03.2007 14:07, Damiano Triglione wrote:

Thanks!
I presumed it expected a signed integer, because if I invoke it with an
unisgned int parameter, I have a warning:
  warning: passing arg 1 of `G_calloc' as signed due to prototype

even if I did not redefine G_calloc anywhere.
Thus, do you think that if I declare in my file
  G_calloc(unsigned int, unsigned int);
I can then eliminate the warning, instead of using a cast in every
invocation?

Damiano

----- Original Message ----- From: "Wolf Bergenheim"
<wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 12:31 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

What? No it doesn't. How do you figure it expects a signed integer?

The definition of G_calloc doesn't have anything to do with how the
compiler thinks it is. Have you redefined G_calloc somewhere? If you
declare in your own file G_calloc(unsigned int, unsigned int); Then the
compiler will think that G_calloc expects two unsigned integers, no
matter how it is really in alloc.c, since the compiler will not look in
alloc.c when compiling your stuff.

--Wolf

On 27.03.2007 12:42, Damiano Triglione wrote:

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of G_calloc
has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

Ahmm I don't remember how GRASS 6.0 or 6.2 was (I'm using 6.3 cvs). Soo
you could try to include gisdefs.h. gisdefs.h is the header which
declares a prototype for G_calloc. Or you could just use calloc / free
(from stdlib.h) instead of G_calloc / G_free, but then you have to check
if calloc returns NULL and call a G_fatal_error or something. Also AFAIK
G_calloc hasn't changed.

--Wolf

On 27.03.2007 15:12, Damiano Triglione wrote:

To be honest, I included "gis.h" because I am still using Grass 6.0, so
- if I am not wring - I should not use <grass/...>.
Maybe I have this kind of problem for this reason?
Do you think that in Grass 6.2.1 the prototype of G_calloc is different
from the one in Grass 6.0?
Damiano

----- Original Message ----- From: "Wolf Bergenheim"
<wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 1:32 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

You probably haven't included <grass/gis.h> which defines a prototype
for G_calloc and friends. The compiler defaults the prototype to
signed int.

So be sure you have a #include <grass/gis.h> in your file where you use
G_calloc, to get the prototype for G_calloc, and get rid of your error.

--Wolf

On 27.03.2007 14:07, Damiano Triglione wrote:

Thanks!
I presumed it expected a signed integer, because if I invoke it with an
unisgned int parameter, I have a warning:
  warning: passing arg 1 of `G_calloc' as signed due to prototype

even if I did not redefine G_calloc anywhere.
Thus, do you think that if I declare in my file
  G_calloc(unsigned int, unsigned int);
I can then eliminate the warning, instead of using a cast in every
invocation?

Damiano

----- Original Message ----- From: "Wolf Bergenheim"
<wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 12:31 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

What? No it doesn't. How do you figure it expects a signed integer?

The definition of G_calloc doesn't have anything to do with how the
compiler thinks it is. Have you redefined G_calloc somewhere? If you
declare in your own file G_calloc(unsigned int, unsigned int); Then the
compiler will think that G_calloc expects two unsigned integers, no
matter how it is really in alloc.c, since the compiler will not look in
alloc.c when compiling your stuff.

--Wolf

On 27.03.2007 12:42, Damiano Triglione wrote:

Hi,
I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type
of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of
G_calloc
has type size_t !
Can anyone, please, help me tu figure out?
Thanks,
Damiano
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--

<:3 )---- Wolf Bergenheim ----( 8:>

--

<:3 )---- Wolf Bergenheim ----( 8:>

OK, thank you for your precious help!
Damiano

----- Original Message ----- From: "Wolf Bergenheim" <wolf+grass@bergenheim.net>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Cc: <grass-dev@grass.itc.it>
Sent: Tuesday, March 27, 2007 2:30 PM
Subject: Re: [GRASS-dev] The "nature" of size_t

Ahmm I don't remember how GRASS 6.0 or 6.2 was (I'm using 6.3 cvs). Soo
you could try to include gisdefs.h. gisdefs.h is the header which
declares a prototype for G_calloc. Or you could just use calloc / free
(from stdlib.h) instead of G_calloc / G_free, but then you have to check
if calloc returns NULL and call a G_fatal_error or something. Also AFAIK
G_calloc hasn't changed.

--Wolf

Damiano Triglione wrote:

I am still trying to understand the "nature" of size_t.
If I am not wrong, it is equivalent to the unsigned integral type of the
result of "sizeof". E.g. in my 32-bit processor PC, it is equal to 4.
But G_calloc() expects - as first argument - a SIGNED (not unsigned)
parameter, even if in alloc.c I find that the first argument of G_calloc has
type size_t !

You seem to be using a fairly old version; 6.0.2 was the last release
where the prototype of G_calloc() used "int"; all of the 6.1/6.2
betas, release candidates and releases have size_t.

--
Glynn Clements <glynn@gclements.plus.com>