🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.hp.hpux
Article #38

Re: struct init problem

#38
From: walter briscoe
Date: Wed, 06 Mar 1996 08:41
67 lines
2709 bytes
In article <DnrAEx.HA@tpoint.net> devil@tpoint.net "The Devil Himself" writes:

> I found that the attached code does not compile on HP's, but does compile on
> UNIXware, etc. I'd like to hear any ideas beside my hacked solution.
> I'm looking for a way to preserve using the struct = { .... } syntax.
> 
> Also, who you characterize this problem vs. ansi C.....

[snip]

>         int     ima_int = 0xdeadbeef ;
>         {
>                 struct test_me please = 
>                 {
>                         0xbeefdead ,
>                         & ima_int 
>                 } ;
> 
>         /*
>          * NOTE: HP-UX foo A.09.05 A 9000/712
>          * wont compile this & ima_int statement, unless I declare
>          * BOTH ima_int AND please as "static". unfortunately, I want this
>          * code to be reenterant.
>          */

As an aside. ints > 16 bits are unportable. long portably meets your
needs.

I regret that the code does not conform with ANSI/ISO 9899-1990.

> 6.5.7 Initialization

[snip]

> All the expressions in an initializer for an object that has static
> storage duration or in an initializer list for an object that has
> aggregate or union type shall be constant expressions.
>
> 6.4 Constant expressions

[snip]

Constraints

[snip]

> A constant expression can be evaluated during translation rather than
> runtime, and accordingly may be used in any place that a constant may
> be.

The address of ima_int is not known at translate time.  I would argue
that any implementation which allows a source containing this code to be
translated without producing a diagnostic is not conforming because:

> 5.1.1.3 Diagnostics
>
> A conforming implementation shall produce at least one diagnostic
> message (identified in an implementation-defined manner) for every
> translation unit that contains a violation of any syntax rule or
> constraint, even if the behavior is also explicitly specified as
> undefined or implementation- defined.  Diagnostic messages need not be
> produced in other circumstances.

I regret that you are stuck with the hack if you want to produce
portable code.
-- 
walter briscoe
Technical Details
Message-ID: <826101714snz@wbriscoe.demon.co.uk>
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!wbriscoe.demon.co.uk
References: <DnrAEx.HA@tpoint.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!wbriscoe.demon.co.uk
From: walter briscoe <walter@wbriscoe.demon.co.uk>
Newsgroups: comp.sys.hp.hpux,comp.std.c,comp.lang.c
Subject: Re: struct init problem
Date: Wed, 06 Mar 96 08:41:54 GMT
Distribution: na
Message-ID: <826101714snz@wbriscoe.demon.co.uk>
References: <DnrAEx.HA@tpoint.net>
Reply-To: walter@wbriscoe.demon.co.uk
X-NNTP-Posting-Host: wbriscoe.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.30
X-Mail2News-Path: wbriscoe.demon.co.uk