Thread View: comp.sys.hp.hpux
3 messages
3 total messages
Started by The Devil Himself
Mon, 04 Mar 1996 18:37
struct init problem
Author: The Devil Himself
Date: Mon, 04 Mar 1996 18:37
Date: Mon, 04 Mar 1996 18:37
58 lines
1663 bytes
1663 bytes
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.....
E-mail answers please....
Thanks - D
_+_+_+_+_+_+_ problem code _+_+_+_+
struct testme
{
int dum_huh ;
int * p ;
} ;
void foofunk( void )
{
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.
*/
}
/* whatever */
}
_+_+_+_+_+_+ hack solution _+_+_+_+_+
void foofunk( void )
{
int ima_int = 0xdeadbeef ;
{
struct test_me please =
{
0xbeefdead ,
} ;
please . p = & ima_int
/* whatever */
}
/* whatever */
}
--
.... (C) 1995 Copyright Duncan Idaho, All Rights Reserved ..................
There are "three absolute rights [sic] the right of personal security, personal
liberty and personal property," Sir William Blackstone. "The protection of
these faculties is the first object of government." Madison, Federalist 10.
Re: struct init problem
Author: walter briscoe
Date: Wed, 06 Mar 1996 08:41
Date: Wed, 06 Mar 1996 08:41
67 lines
2709 bytes
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
Re: struct init problem
Author: Lawrence Kirby
Date: Wed, 06 Mar 1996 14:30
Date: Wed, 06 Mar 1996 14:30
68 lines
3112 bytes
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
-----------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads