comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing with C ; an ununsed fields dilemma
@ 2009-07-02  6:20 Hibou57 (Yannick Duchêne)
  2009-07-02  9:25 ` Martin
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-07-02  6:20 UTC (permalink / raw)


Hello to all,

Once again, a topic about interfacing with C structures.

A lot of C structure are defined with so called “ unused field
reserved for future use ” (oftenly never used in any future). This
fields are generally to be initialized to zero, what is required, to
unsure it will not be errorneously interpreted by the exogenous part
of the application, specially if it is dynamically linked to the
application (beceause then, its version or its implementation may be
differente and unknown of the application which rely on it).

And here is the dilemma :

Using clause representation, it is tempting to simply drop this
unuseful unusedfields from the visible part of the declaration (yeah
dear friend, lot cleaner, really tempting), and simply assigning
nothing to this bit-range in the record representation clause.

But doing so disallow to tell the compiler these fields are to be
initialized to “ zero ” (at the binary level). And that is less nice.

So a question may comes here : either a way to tell the compiler that
bit-range left unassigned in the representation clause are all zero-
bits when an instance of such a record is created by the application,

I've looked at the ARM, and found a sole place about this topic of
filling gaps :

Annotated RM 2005 says
> 22 * An implementation need not support a component_clause for a component of
> an extension part if the storage place is not after the storage places of
> all components of the parent type, whether or not those storage places had
> been specified.
>
> 22.a Reason: These restrictions are probably necessary if block equality
> operations are to be feasible for class-wide types. For block comparison to
> work, the implementation typically has to fill in any gaps with zero (or
> one) bits. If a “gap” in the parent type is filled in with a component in a
> type extension, then this won't work when a class-wide object is passed by
> reference, as is required.

Ok, for the block comparison to work, implementation tipically fill
gaps with zero bits.... but what if no block comparison is ever used
in the application ? Is this behaviour droped ? Further more, this is
not an implementation requirement, so it is not possible to formally
rely on it.

Is there another RM entry you know about it ? Is there any running Ada
Issues about a suggestion to make this behaviour a formalized
behaviour (a syntax to tell that gaps are to be filled with zero...
and perhaps 1 as well by the way)

Pleased to read you and have a nice day :)



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

end of thread, other threads:[~2009-07-04  0:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-02  6:20 Interfacing with C ; an ununsed fields dilemma Hibou57 (Yannick Duchêne)
2009-07-02  9:25 ` Martin
2009-07-02 18:14   ` reserved fields; was " tmoran
2009-07-02  9:45 ` Maciej Sobczak
2009-07-02 12:01   ` Hibou57 (Yannick Duchêne)
2009-07-02 12:09     ` Georg Bauhaus
2009-07-02 13:21       ` Hibou57 (Yannick Duchêne)
2009-07-02 15:50         ` Georg Bauhaus
2009-07-02 14:52     ` Maciej Sobczak
2009-07-02 23:21       ` Hibou57 (Yannick Duchêne)
2009-07-03  7:21         ` Maciej Sobczak
2009-07-02  9:51 ` Georg Bauhaus
2009-07-02 10:16   ` Martin
2009-07-02 11:48     ` Hibou57 (Yannick Duchêne)
2009-07-02 15:55 ` Robert A Duff
2009-07-04  0:03   ` Randy Brukardt
2009-07-03  6:59 ` anon

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