🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: struct init problem

#37
From: Lawrence Kirby
Date: Wed, 06 Mar 1996 14:30
68 lines
3112 bytes
In article <826101714snz@wbriscoe.demon.co.uk>
           walter@wbriscoe.demon.co.uk "walter briscoe" writes:

>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.
>>          */

Compound initialisers must consist of constant expression which means that
ima_int must have static storage duration for this code to be portable.
There is no requirement for please to be static. However if you are using
a pre-ANSI compiler in the HP-UX system there is a good chance that it
won't accept auto struct initialisation. If ima_int really needs to be
an auto variable (you mentioned recursion) then you can't use structure
initialisation portably.

>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.
>>
...

>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:

You're missing the following in 6.4:

"An implementation may accept other forms of constant expressions."

So the UNIXware compiler can legally accept &ima_int as a constant
expression so long as it does so consistently. However code that uses
this isn't strictly conforming.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID: <826122618snz@genesis.demon.co.uk>
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk
References: <DnrAEx.HA@tpoint.net> <826101714snz@wbriscoe.demon.co.uk>

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