Operating System - HP-UX
1833346 Members
2911 Online
110051 Solutions
New Discussion

Porting C program from MS Visual C++

 
Tony Bentley_1
Occasional Contributor

Porting C program from MS Visual C++

Hi everyone,

I have many C programs which compile under MS Visual C++ but not on HP C/ansi C or HP C++ compiler. The problem is around structures. Is there an option on either of the HP Compilers which I can use to allow these structures to work as written?

A snip of the code:
struct w_ioa_000
{
struct
{
char hipaa_manager_name_001as;
char hipaa_manager_name_001[49] /* 48 + 1 */;
char hipaa_queue_name_001as;
char hipaa_queue_name_001[49] /* 48 + 1 */;
char hipaa_exception_queue_na_002as;
char hipaa_exception_queue_name_002[49] /* 48 + 1 */;
char hipaa_mq_time_out_002as;
char hipaa_mq_time_out_002[6] /* 5 + 1 */;
};
};

Error message while compiling:

cc: "EABCL837.c", line 46: warning 500: Unnamed struct/union members are ignored.
cc: "EABCL837.c", line 44: error 1613: Zero-sized struct.


Compile line:
cc -Aa -c +z -DTARGET_HPUX -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_POSIX_SOURCE +DAportable -I/t07/m2
10/extrn/include -o/t07/m210/extrn/src/EABCL837.o /t07/m210/extrn/src/EABCL837.c

Thoughts?

Thanks,
Tony
3 REPLIES 3
Don Morris_1
Honored Contributor

Re: Porting C program from MS Visual C++

Just off the cuff -- have you tried giving a name to the encapsulated struct? That's certainly what the compiler error seems to be complaining about.

(Which also makes me wonder how you referenced those fields in Visual C++ -- I've never tried using an unlabeled struct as a field of a labeled one.)
A. Clay Stephenson
Acclaimed Contributor

Re: Porting C program from MS Visual C++

Hi Tony:

Sorry, there is no #pragma or compiler option
to fix? this. The fundamental problem is that as declared the nested struct has no variable associated with so that the compiler cannot calculate sizes. Moreover, there is no way to address any component of the nested struct without an associated name. Even naming the nested struct e.g struct dummy doesn't help because it does not address the space allocation (or addressing) issue.

The real fix is to make your code portable by
changed to something like this:

struct w_ioa_000
{
struct MY_STRUCT
{
char hipaa_manager_name_001as;
char hipaa_manager_name_001[49] /* 48 + 1 */;
char hipaa_queue_name_001as;
char hipaa_queue_name_001[49] /* 48 + 1 */;
char hipaa_exception_queue_na_002as;
char hipaa_exception_queue_name_002[49] /* 48 + 1 */;
char hipaa_mq_time_out_002as;
char hipaa_mq_time_out_002[6] /* 5 + 1 */;
} DUMMY;
};

If you have a large amount of code to change, you could probably do this with perl or awk.

Clay


If it ain't broke, I can fix that.
Tony Bentley_1
Occasional Contributor

Re: Porting C program from MS Visual C++

Thanks for the replies. Yes there is a larger amount of code to be changed. A script or Perl script was discussed, but that looks like the answer.

Thanks.

Tony