473,396 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unnamed struct members allowed?

I've a CICS program that uses BMS maps. Our wysiwyg map editor produces
it's source in COBOL so I am manually creating C unions to match the
COBOL output. Can I convert the FILLER statements to unnamed struct
members or am I stuck with the scenario using filler0, filler1, filler2
etc. ?
01 PIDCI.
02 FILLER PICTURE X(12).
02 MAPTRANIDL COMP PICTURE S9(4).
02 MAPTRANIDF PICTURE X.
02 FILLER PICTURE X(04).
02 MAPTRANIDI PICTURE X(04).
etc...
etc...
etc...
01 PIDCO REDEFINES PIDCI.
02 FILLER PICTURE X(12).
02 FILLER PICTURE X(02).
02 MAPTRANIDA PICTURE X.
02 MAPTRANIDC PICTURE X.
02 MAPTRANIDP PICTURE X.
02 MAPTRANIDH PICTURE X.
02 MAPTRANIDV PICTURE X.
02 MAPTRANIDO PICTURE X(04).
02 FILLER PICTURE X(02).
etc...
etc...
etc...
union pidc {
struct pidci {
unsigned char filler0??(12??); /* <---<< here */
int maptranidl;
unsigned char maptranidf;
unsigned char filler1??(4??); /* <---<< here */
unsigned char maptranidi??(4??);
etc...
etc...
etc...
} pidci; /* struct pidci */

struct pidco {
unsigned char filler0??(12??); /* <---<< here */
unsigned char filler1??(2??); /* <---<< here */
unsigned char maptranida;
unsigned char maptranidc;
unsigned char maptranidp;
unsigned char maptranidh;
unsigned char maptranidv;
unsigned char maptranido??(4??);
unsigned char filler2??(2??); /* <---<< here */
etc...
etc...
etc...
} pidco; /* struc pidco */
} pidc; /* union pidc */

Jun 15 '06 #1
12 7663
In article <11*********************@c74g2000cwc.googlegroups. com>,
Jalapeno <ja*******@mac.com> wrote:
I've a CICS program that uses BMS maps. Our wysiwyg map editor produces
it's source in COBOL so I am manually creating C unions to match the
COBOL output. Can I convert the FILLER statements to unnamed struct
members or am I stuck with the scenario using filler0, filler1, filler2
etc. ?


Within a C struct: sorry, no, every field must be named
[with the exception of a bitfield specified as :0 -- which has
to do with bitfield alignment and has no practical value for
your situation.]
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Jun 15 '06 #2
Walter Roberson wrote:
Jalapeno <ja*******@mac.com> wrote:
I've a CICS program that uses BMS maps. Our wysiwyg map editor
produces it's source in COBOL so I am manually creating C unions
to match the COBOL output. Can I convert the FILLER statements
to unnamed struct members or am I stuck with the scenario using
filler0, filler1, filler2 etc. ?


Within a C struct: sorry, no, every field must be named
[with the exception of a bitfield specified as :0 -- which has
to do with bitfield alignment and has no practical value for
your situation.]


He was also reflecting a COMP 4 item as an int. Even if the
storage is the same, there may be alignment problems handled by
Cobol, but not C. IIRC, it's been at least 20 years since I did
any Cobol. Not greatly missed.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Jun 15 '06 #3
CBFalconer wrote:

Walter Roberson wrote:
Jalapeno <ja*******@mac.com> wrote:
I've a CICS program that uses BMS maps. Our wysiwyg map editor
produces it's source in COBOL so I am manually creating C unions
to match the COBOL output. Can I convert the FILLER statements
to unnamed struct members or am I stuck with the scenario using
filler0, filler1, filler2 etc. ?


Within a C struct: sorry, no, every field must be named
[with the exception of a bitfield specified as :0 -- which has
to do with bitfield alignment and has no practical value for
your situation.]


He was also reflecting a COMP 4 item as an int. Even if the
storage is the same, there may be alignment problems handled by
Cobol, but not C. IIRC, it's been at least 20 years since I did
any Cobol. Not greatly missed.

I do miss writing in Cobol, and I miss it quite pleasantly TYVM.

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Jun 16 '06 #4
Walter Roberson wrote:
In article <11*********************@c74g2000cwc.googlegroups. com>,
Jalapeno <ja*******@mac.com> wrote:
Can I convert the FILLER statements to unnamed struct
members or am I stuck with the scenario using filler0, filler1, filler2
etc. ?


Within a C struct: sorry, no, every field must be named


Thanks. I'm currently programming in COBOL, REXX, and C and maintaining
old BAL, CLIST and PL/I code and sometimes get the features mixed up.

Jun 16 '06 #5

CBFalconer wrote:
Walter Roberson wrote:
Jalapeno <ja*******@mac.com> wrote:
Our wysiwyg map editor produces it's source in COBOL so I am manually creating C unions
to match the COBOL output.
Within a C struct: sorry, no,


He was also reflecting a COMP 4 item as an int. Even if the
storage is the same, there may be alignment problems handled by
Cobol, but not C.


COMP S9(4) is a 32 bit signed computational field. It translates to int
with z/OS C compilers. It may not on other platforms but CICS regions
are sparse outside of z/OS (although I do have CICS for Windows loaded
on my PC and I've read some shops still use CICS for VSE).
... IIRC, it's been at least 20 years since I did
any Cobol. Not greatly missed.


I have no particular love for COBOL myself and I moved into CICS
systems programming when my COBOL application job went to India.
Unfortunately, we systems programmers are now spending half our time
"teaching" outsourced applications programmers how to do the jobs they
took from us.

Jun 16 '06 #6
"Jalapeno" <ja*******@mac.com> wrote:
# I've a CICS program that uses BMS maps. Our wysiwyg map editor produces
# it's source in COBOL so I am manually creating C unions to match the
# COBOL output. Can I convert the FILLER statements to unnamed struct
# members or am I stuck with the scenario using filler0, filler1, filler2
# etc. ?

Unless you're exploiting compiler specific options, you cannot
depend on struct fields ending up on any particular byte or bit
boundary.

An alternative way is to use a char array and place fields
manually. Such as

# 01 PIDCI.
# 02 FILLER PICTURE X(12).
# 02 MAPTRANIDL COMP PICTURE S9(4).
# 02 MAPTRANIDF PICTURE X.
# 02 FILLER PICTURE X(04).
# 02 MAPTRANIDI PICTURE X(04).

typedef char PIDCI[12+4+1+4+4+...];
enum {
oPIDC1MAPTRANIDL = 12, lPIDC1MAPTRANIDL = 4,
oPIDC1MAPTRANIDF = 12+4, lPIDC1MAPTRANIDF = 1,
oPIDC1MAPTRANIDI = 12+4+1+4, lPIDC1MAPTRANIDI = 4,
...
};
int getInt1(char *a,int o,int l) {
int r = 0; memcpy(&r,a+o,l); return r;
}
void putInt1(char *a,int o,int l,int v) {
int r = v; memcpy(a+o,&r,l);
}

#define getInt(a,field) (getInt1(a,o##field,l##field))
#define putInt(a,field,v) (putInt1(a,o##field,l##field,v))

#define getChar(a,field) ((a)[o##field])
#define putChar(a,field,v) ((a)[o##field]=(v))

#define getChars(a,field,r) (memcpy(r,(a)+o##field,l##field))
#define putChars(a,field,v) (memcpy((a)+o##field,v,l##field))

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
Jun 16 '06 #7

SM Ryan wrote:

Unless you're exploiting compiler specific options, you cannot
depend on struct fields ending up on any particular byte or bit
boundary.


How the struct members are aligned is documented for both C and COBOL.
Without getting into off topic details, the COBOL and C compilers
"working storage"/"automatic variables" in CICS match the layout of the
BMS assembler macro. My job as a C programmer in this instance is
basically to make sure the C type matches the COBOL type and let the
compiler do the work. Using an unsigned (or plain) char array is, I
believe, actually treading on ice-more-thin in this situation. Thanks
for the interesting idea. My question was really about C's syntax
rather than about converting COBOL.

Jun 16 '06 #8

Jalapeno wrote:
Unfortunately, we systems programmers are now spending half our time
"teaching" outsourced applications programmers how to do the jobs they
took from us.


After rereading what I wrote here it sounds more harsh than I intended.
I have nothing against folks competing in a global economy. I work with
individuals who are quite bright. If I have a beef it is with
outsourcing companies that get a contract, hire newby programmers, give
them a few weeks training, and then put them on the job less than half
prepared. I hope I did not offend anyone with that statement.

Jun 16 '06 #9
"Jalapeno" <ja*******@mac.com> writes:
SM Ryan wrote:
Unless you're exploiting compiler specific options, you cannot
depend on struct fields ending up on any particular byte or bit
boundary.


How the struct members are aligned is documented for both C and COBOL.


Correction: it may be documented for your particular implementation.
The C standard makes only a few guarantees about how struct members
are allocated. A compiler may insert arbitrary padding between
members, or after the last member. I don't believe it's even required
to document how it does so, or to behave consistently across different
phases of the moon.

If you're working in an environment that makes additional guarantees,
of course, you're free to depend on those guarantees; just be aware
that your code could break if it's ported to another implementation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 16 '06 #10
Jalapeno wrote:
SM Ryan wrote:

Unless you're exploiting compiler specific options, you cannot
depend on struct fields ending up on any particular byte or bit
boundary.


How the struct members are aligned is documented for both C and COBOL.

.... snip ...

Not for C it isn't. I believe the only guarantee you have is that
the address of the first component is also the address of the
complete structure.

--
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Jun 16 '06 #11
CBFalconer <cb********@yahoo.com> writes:
Jalapeno wrote:
SM Ryan wrote:

Unless you're exploiting compiler specific options, you cannot
depend on struct fields ending up on any particular byte or bit
boundary.


How the struct members are aligned is documented for both C and COBOL.

... snip ...

Not for C it isn't. I believe the only guarantee you have is that
the address of the first component is also the address of the
complete structure.


And that addresses of other members increase in the order in which
they're declared, and (implicitly) that the layout leaves at least
enough room for each member.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 16 '06 #12
# How the struct members are aligned is documented for both C and COBOL.
# Without getting into off topic details, the COBOL and C compilers

For a specific C compiler. Other C compilers might lay out a
struct differently. The first field is at the very beginning
of the struct, and subsequent fields are strictly increasing
offsets, but there's no guarentee by the language definition
what those offsets will be.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I love the smell of commerce in the morning.
Jun 16 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank Roland | last post by:
I know it is possible to use unnamed struct or unions inside of struct like in the following example: typedef struct { union { int moin; char carl; }; int bon; } dastruct;
21
by: hermes_917 | last post by:
I want to use memcpy to copy the contents of one struct to another which is a superset of the original struct (the second struct has extra members at the end). I wrote a small program to test...
7
by: Roman Mashak | last post by:
Hello, All! I'm trying to compile some driver for MIPS target, and get errors. I assumed these may be related to C language. tigon3.h:2225: unnamed fields of type other than struct or union...
5
by: jaso | last post by:
Hi, If have a structure of a database record like this: struct record { char id; char title; ... }; Is there some way to find out how many member variables there is in the struct and then...
9
by: Tom Plunket | last post by:
The project I'm currently on makes heavy use of unnamed structures to represent an "object hierarchy" of a sort. E.g. struct BaseObject { int aMember; int anotherMember; // etc.
21
by: Zytan | last post by:
Is it possible, as in C? I don't think it is. Just checking. Zytan
18
by: Ehud Shapira | last post by:
Is it possible to have a declaration of a struct pointer initialized to an unnamed struct? (I'm only concerned with static/global variables, if it matters.) I'm trying to do something like: ...
6
by: ssubbarayan | last post by:
Dear all, I developed the following program: void parsebytes(unsigned char* data); struct info { unsigned char day; unsigned char month; short year;
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.