comp.lang.ada
 help / color / mirror / Atom feed
* how to know sizeof(int)
@ 2004-08-04 14:58 Evangelista Sami
  2004-08-04 15:18 ` Eric Jacoboni
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Evangelista Sami @ 2004-08-04 14:58 UTC (permalink / raw)


hello

how can i know the result of a sizeof(int) (in C).
i did not find the approppriate stuffs in interfaces.C.

Thanks

Sami



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 14:58 how to know sizeof(int) Evangelista Sami
@ 2004-08-04 15:18 ` Eric Jacoboni
  2004-08-04 15:26 ` Adrian Knoth
  2004-08-04 15:32 ` Jean-Pierre Rosen
  2 siblings, 0 replies; 9+ messages in thread
From: Eric Jacoboni @ 2004-08-04 15:18 UTC (permalink / raw)


evangeli@cnam.fr (Evangelista Sami) writes:

> how can i know the result of a sizeof(int) (in C).
> i did not find the approppriate stuffs in interfaces.C.

What about the Size attribute ?


procedure Test_Interface_C is

   Int_C : Int := 100;

begin
   Put_Line(Int'Image(Int'First) & ".." & Int'Image(Int'Last))    -- -2147483648.. 2147483647
   Put_Line(Integer'Image(Int_C'Size));                           -- 32 here
end;


-- 
�ric Jacoboni, n� il y a 1395076360 secondes



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 14:58 how to know sizeof(int) Evangelista Sami
  2004-08-04 15:18 ` Eric Jacoboni
@ 2004-08-04 15:26 ` Adrian Knoth
  2004-08-04 15:32 ` Jean-Pierre Rosen
  2 siblings, 0 replies; 9+ messages in thread
From: Adrian Knoth @ 2004-08-04 15:26 UTC (permalink / raw)


Evangelista Sami <evangeli@cnam.fr> wrote:

> how can i know the result of a sizeof(int) (in C).

Run it at compile-time?



-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Ich kann allem widerstehen, nur nicht der Versuchung



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 14:58 how to know sizeof(int) Evangelista Sami
  2004-08-04 15:18 ` Eric Jacoboni
  2004-08-04 15:26 ` Adrian Knoth
@ 2004-08-04 15:32 ` Jean-Pierre Rosen
  2004-08-04 19:06   ` Ludovic Brenta
  2004-08-04 21:52   ` Adrian Knoth
  2 siblings, 2 replies; 9+ messages in thread
From: Jean-Pierre Rosen @ 2004-08-04 15:32 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]


"Evangelista Sami" <evangeli@cnam.fr> a �crit dans le message de news:5f59677c.0408040658.5976777a@posting.google.com...
> hello
>
> how can i know the result of a sizeof(int) (in C).
> i did not find the approppriate stuffs in interfaces.C.
>
Interfaces.C.Int'Size/8

Interfaces.C.Int is the same as C Int, but the Size attributes is in bits, not bytes (OK, I assume here that a byte is 8 bits :-).

Note that sizeof is *not* a regular function (a regular function could not have a type as the parameter). It is handled very
specially in the C compiler, therefore there is no way you could get to it from another language.

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 15:32 ` Jean-Pierre Rosen
@ 2004-08-04 19:06   ` Ludovic Brenta
  2004-08-05  8:14     ` Jean-Pierre Rosen
  2004-08-04 21:52   ` Adrian Knoth
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Brenta @ 2004-08-04 19:06 UTC (permalink / raw)


"Jean-Pierre Rosen" writes:
> "Evangelista Sami" a écrit dans le message de hello
>>
>> how can i know the result of a sizeof(int) (in C).
>> i did not find the approppriate stuffs in interfaces.C.
>>
> Interfaces.C.Int'Size/8
>
> Interfaces.C.Int is the same as C Int, but the Size attributes is in
> bits, not bytes (OK, I assume here that a byte is 8 bits :-).

Indeed, hidden assumptions are evil, and the Enlightened Ones use
System.Storage_Unit instead of just "8".  Somehow, "8" is too short to
type and read :)

> Note that sizeof is *not* a regular function (a regular function
> could not have a type as the parameter). It is handled very
> specially in the C compiler, therefore there is no way you could get
> to it from another language.

I suppose 'Size is also handled specially by Ada compilers, right?

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 15:32 ` Jean-Pierre Rosen
  2004-08-04 19:06   ` Ludovic Brenta
@ 2004-08-04 21:52   ` Adrian Knoth
  2004-08-05  8:16     ` Jean-Pierre Rosen
  1 sibling, 1 reply; 9+ messages in thread
From: Adrian Knoth @ 2004-08-04 21:52 UTC (permalink / raw)


Jean-Pierre Rosen <rosen@adalog.fr> wrote:

>> how can i know the result of a sizeof(int) (in C).
>> i did not find the approppriate stuffs in interfaces.C.
> Interfaces.C.Int'Size/8

Is it specific to a single compiler? How can someone (gnat) know
about the size of an Integer in C? The standard doesn't define it,
does it?

As far as I know the size of internal datatyes is compiler-dependent.

-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

We are born for Appelkorn!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 19:06   ` Ludovic Brenta
@ 2004-08-05  8:14     ` Jean-Pierre Rosen
  2004-08-07  4:09       ` Keith Thompson
  0 siblings, 1 reply; 9+ messages in thread
From: Jean-Pierre Rosen @ 2004-08-05  8:14 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1218 bytes --]


"Ludovic Brenta" <ludovic.brenta@insalien.org> a �crit dans le message de news:87llguk9k1.fsf@insalien.org...
> Indeed, hidden assumptions are evil, and the Enlightened Ones use
> System.Storage_Unit instead of just "8".  Somehow, "8" is too short to
> type and read :)
Sure, but we are in a C context here. Try to explain to a C programmer that a byte does not necessarily have eight bits :-)

> > Note that sizeof is *not* a regular function (a regular function
> > could not have a type as the parameter). It is handled very
> > specially in the C compiler, therefore there is no way you could get
> > to it from another language.
>
> I suppose 'Size is also handled specially by Ada compilers, right?
All attributes are handled specially of course, but it is explicit. The goal of having a special syntax for attributes is to avoid
*hidden* magic, and by the way, it is why it is a good thing that users are not allowed to define their own attributes.
It saves you from interesting question like "what happens if a user defines a function called sizeof?".

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-04 21:52   ` Adrian Knoth
@ 2004-08-05  8:16     ` Jean-Pierre Rosen
  0 siblings, 0 replies; 9+ messages in thread
From: Jean-Pierre Rosen @ 2004-08-05  8:16 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 922 bytes --]


"Adrian Knoth" <adi@thur.de> a �crit dans le message de news:slrnch2mlq.5o5.adi@ppc201.mipool.uni-jena.de...
> Jean-Pierre Rosen <rosen@adalog.fr> wrote:
>
> >> how can i know the result of a sizeof(int) (in C).
> >> i did not find the approppriate stuffs in interfaces.C.
> > Interfaces.C.Int'Size/8
>
> Is it specific to a single compiler? How can someone (gnat) know
> about the size of an Integer in C? The standard doesn't define it,
> does it?
>
> As far as I know the size of internal datatyes is compiler-dependent.
Sure - but the definition of Interfaces.C.Int is guaranteed to match the definition of Int in C, or at least in the C compiler you
are interfacing to. Remember you never interface with another language, you interface with another compiler!

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to know sizeof(int)
  2004-08-05  8:14     ` Jean-Pierre Rosen
@ 2004-08-07  4:09       ` Keith Thompson
  0 siblings, 0 replies; 9+ messages in thread
From: Keith Thompson @ 2004-08-07  4:09 UTC (permalink / raw)


"Jean-Pierre Rosen" <rosen@adalog.fr> writes:
> "Ludovic Brenta" <ludovic.brenta@insalien.org> a �crit dans le
> message de news:87llguk9k1.fsf@insalien.org...
> > Indeed, hidden assumptions are evil, and the Enlightened Ones use
> > System.Storage_Unit instead of just "8".  Somehow, "8" is too short to
> > type and read :)
> Sure, but we are in a C context here. Try to explain to a C
> programmer that a byte does not necessarily have eight bits :-)

To a C programmer, a byte doesn't necessarily have 8 bits.  The C
standard guarantees that a byte is *at least* 8 bits, but there are
systems with larger bytes (I think 32 is typical for DSPs).

In C, the number of bits in a byte is determined by the macro CHAR_BIT
in <limits.h>.

You can't necessarily assume that C's CHAR_BIT is the same as Ada's
System.Storage_Unit, but I'd be very surprised to see a system where
they're different.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-08-07  4:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-04 14:58 how to know sizeof(int) Evangelista Sami
2004-08-04 15:18 ` Eric Jacoboni
2004-08-04 15:26 ` Adrian Knoth
2004-08-04 15:32 ` Jean-Pierre Rosen
2004-08-04 19:06   ` Ludovic Brenta
2004-08-05  8:14     ` Jean-Pierre Rosen
2004-08-07  4:09       ` Keith Thompson
2004-08-04 21:52   ` Adrian Knoth
2004-08-05  8:16     ` Jean-Pierre Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox