Operating System - OpenVMS
1827500 Members
3442 Online
109965 Solutions
New Discussion

C Structures, Pointers and Itanium and ALPHA VMS

 
CA1296764
Advisor

C Structures, Pointers and Itanium and ALPHA VMS

Hi again,

I have some complicated code which works on VMS ALPHA
(DEC C V6.0-001 on OpenVMS Alpha V7.1-2)
but not yet on VMS Itanium (HP C V7.1-011 on OpenVMS IA64 V8.2-1).

I posted the original question a few weeks ago and I still have not fixed the code,
but I have narrowed the problems down to reproducable code.

The full source of the test program is about 750 lines in one source file with comments
and a lot of declarations to get the above to work.....
next task is to reduce the test program to isolate the issue/problem.....)

The code uses a lot of structs, typedefs and pointer arthimetic.

The main problem I have having is as follows in code snippets around the following typedef:

1 typedef struct FtamApiParDef {
2 int iFtamPort;
3 int iApiStatus;
4 int iFtamStatus;
5 int iFtamCommand;
6 osifpbType *pResultpb;
7 osifpbType *pOsifpb[MaxParameterBlockNumbers];
8 struct osifpb *pOsifpbtest[MaxParameterBlockNumbers];
9 osif_buffer_listType *pBufferList[MaxOsifBuffers];
10 RecordInfoType RecordInfo;
11 char scratch[32];
12 } FtamApiParType;

Notes:
(Line 8 is added by myself to try and debug this code)
Lines 7 and 8 above are equivilent as osifpbType is typedef's as struct osifpb, and the struct
osifpb is defined in the standard header sys$library:osif.h
thus giving an array of pointers to structures
MaxParameterBlockNumbers is defined as follows:

enum ParameterBlockNumbers {
BeginGroupParameterBlock,
SelectParameterBlock,
OpenParameterBlock,
EndGroupParameterBlock,
MaxParameterBlockNumbers };

The above typedefs are then used to define a pointer variable as
follows to use the defined structure:

FtamApiParType *FTAM_api_data;

When the program runs in Debug on VMS Alpha I get what I require when looking at
FTAM_api_data[0].pResultpb
FTAM_api_data[0].pOsifpb[0]
ie they both return addresses (or an array of addresses) that are then
pointers to the osifpb structures defined.

On VMS Itanium I do not get the same behaviour
FTAM_api_data[0].pResultpb returns a pointer address as expected.
BUT FTAM_api_data[0].pOsifpb[0] returns the something like the following:

DBG> ex FTAM_api_data[0].pOsifpbtest
TEST\main\%LINE 9449\FTAM_api_data[0].pOsifpbtest[0:3]
[0]: 48925241413831804751116003009695900761194800108916740805498008442293941802393281179557430083179543281820765249658043
96239402714093723528293514634452579354948479781822283484391278
[1]: 11391295449303417641463690206803358337188791508999825642792975633007926354741975939729583934689765628851197019605441
94150576999898469897055419775297068840579241463407474
[2]: 26522426515127107597570145052865516248133013744372468541359937826655633642203118511777333763171373002350323413511370
1725047314515912415705486148432146022231141
[3]: 61752336367795028718118893571350528505009165369841429734043632230385284969124753288406258828871354931849807997959130
845276479263769559493634418685023

Also on VMS Itanium when values are set to the structure items below pOsifpb and pOsifpbtest they corrupt the
values stored in pOsifpb and pOsifpbtest.

On Alpha VMS I get the following, whih I think is what I am expecting for pointers:
DBG> ex FTAM_api_data[0].pOsifpbtest
TEST\main\%LINE 9449\FTAM_api_data[0].pOsifpbtest[0:3]
[0]: 0000000000
[1]: 0000000000
[2]: 0000000000
[3]: 0000000000


Can anyone shed any light on what I am seeing here and why it works on the old compiler on
Alpha VMS but not on the new C complier on Itanium?

Is the pointer arthmetic correct or are the definitions incorrect.

Where is all the extra data coming from in the debugger on Itanium, ie not pointer addresses?

Many thanks
JC

2 REPLIES 2
Robert Gezelter
Honored Contributor

Re: C Structures, Pointers and Itanium and ALPHA VMS

JC_UK,

Before we get wrapped up in this, please ensure that you are working with UNOPTIMIZED code on both systems.

Let me preface the following by observing that I have been working since 0430 EDT here in New York.

At first glance, it would appear that FTAM_api_data is NOT an array. The following line (extracted from your posting):

FtamApiParType *FTAM_api_data;

defines a scalar, not an array. I don't have the C/C++ syntax description handy (and I will accept correction from somebody who DOES have the manual handy), but at first impression this looks like a marginal, if not incorrect syntax.

If I am correct, you have fallen victim to the syndrome of marginally legal code (which VAX C users well remember). In these cases, the code accidentally works for a while, until the compiler, optimizer, run-time library, or operating system decide to enforce the rules more literally.

However, as I said, just a flash reading of the code.

- Bob Gezelter, http://www.rlgsc.com
Steven Schweda
Honored Contributor

Re: C Structures, Pointers and Itanium and ALPHA VMS

> FtamApiParType *FTAM_api_data;
> defines a scalar, not an array.

Don't worry about it. C pointer names and
array names are still pretty much
interchangeable (or should be), even on IA64.

Personally, I'd probably add some printf()
statements to the code and display some of
the addresses involved to see if anyone is
making any sense. When the debugger stops
making sense, it's time to go elsewhere for
useful information.

Of course, I always tend to prefer the simple
to the sophisticated. (And downright crude
is even better than simple, I claim.)