Re: partially initialized structures in C (3)
Hello Dave, thank you for your answers. Yes, the reason for my confusion was twofold: first, the documentation of IBM, which states that the remaining components of partially initialized automatic structures are not initialized, which is not conforming to the ANSI standard and is not what the compilers do and second, the fact, that the MVI, which sets the first byte of the remainder of the structure to zero and the MVC, which does the rest, are separated by some 40 instructions from each other, so I didn't see the MVC at first look (the function prologue is located between these instructions) But, thanks to the mailing list, I had some closer looks and found the MVCs in the end, which ended my confusion and the whole mess. And: thank you for your advertisement. I like your compiler, but I will not be able to convince my customer to try it - they are very IBM bound, in my opinion. Kind regards Bernd Thomas David Rivers schrieb: I'm pretty confident the IBM compiler follows the ANSI C standard and that some other reason is the cause of the confusion. If you discover it doesn't, and it's a problem; might I humbly offer our alternative (which can operate in your LE environment.) We definately would initialize that structure to all zeros. And, if you're recompiling anyway... might as well give our compiler a try... Just a (partially shameless) plug. - Dave Rivers - -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
To David: no, there is no MVC. This is the z/OS V1.6 C-Compiler. I will try and examine the newer versions. Maybe the error is only in this version. But the description in the language reference also tells that the remaining components remain uninitialized, which is very strange. We, too, do this initialization all the time. That's why we feel in trouble now. Most of the time, the areas are explicitly initalized later, anyway, so there is no problem. But in this case, it is not. But still, most of the time, the area is zero, because it has not been used before. So there is still no problem. We observed this problem in the last week for the first time and it took us several hours to find the reason for it. To Charles: The next component is not char, so it makes no sense to simply put a single hex zero in front of it. The only good reason for the MVI would be if a overlapped MVC would follow. Kind regards Bernd David Crayford schrieb: Are you sure there isn't an MVC after the MVI? I rely on that kind of initialization all the time and have never had a problem. A quick test program shows the correct behavior. If this is not working as the ANSI standard I suggest you open a PMR. To circumvent the problem compile with INITAUTO(0). * * struct F * { * int a; * char string[20];* short s;* }; * *struct F f = {0}; LA r0,0 ST r0,f.F.a(,r4,2016) MVI f(r4,2020),0 MVC f(23,r4,2021),f(r4,2020) Compiled with CHECKOUT compiler option generates the following message. INFORMATIONAL CCN3447 DOC.C(F1):14The member(s) starting from string will be initialized with a default value of 0. Bernd Oppolzer wrote: Sorry for the missing line feeds. C statement: *scp1215ein in1215 = { 0 }; Pseudo ASSEMBLER (structure starts at 272(r13)): STr6,a5:d272:l4(,r13,272) MVI a5:d276:l1(r13,276),0 C statement: *scp1215aus out1215= { 0 }; Pseudo ASSEMBLER (structure starts at 296(r13)): STr6,a5:d296:l4(,r13,296) MVI a5:d300:l1(r13,300),0 Kind regards Bernd Bernd Oppolzer schrieb: To make it clear: see above The ST operations initialize the first components of the structures, which are fullwords. This is what should be done, according to the IBM C language reference. The rest of the structures should remain unchanged (uninitialized), according to IBM's language reference, and should be set to zero, according to ANSI C language reference. The structure out1215, for example, is 24 bytes long. Now the MVI makes absolutely no sense to me. It would only make some sense, if it was followed by an overlapped MVC instruction, which would set the rest of the structure to zero. But such a instruction is not generated by the compiler. ??? Kind regards Bernd Bernd Oppolzer schrieb: Hello all, sorry for asking this question on IBM-Main, but the C370 list is so silent that I doubt that anyone is actually listening. We observed a sort of problem today which showed up as a 0C4 abend due to a not proper initialized pointer component of a C structure. Further examination showed that the structured was initialized as follows structure_type structure_identified = { 0 }; The structure has several components; the last component is the pointer. According to the IBM C language reference, only the first component is initialized to zero, and the other components have random contents, because the storage class is automatic. The compiler generates only initialization logic for the first few bytes of the auto structure. So from this point of view, everything is right. But: the ANSI C language reference, for example in the Kernighan Ritchie book appendix, and most other C language references I found on the web, clearly state that if the number of initializers on structure initialization is less than the number of structure components, the remaining components are initialized to zero, even for auto structures. This is not an error in that sense that the compiler does not what is written in the language reference, but instead it is a contradiction between IBM's language reference and ANSI language reference. What do you think about this? Does it make sense to complain at IBM about it? We have hundreds of C programs in production use which use this kind of initialization (maybe) and now we are afraid that we need to examine all these programs. Kind regards Bernd -- For IBM-MAIN
Re: partially initialized structures in C (3)
Hello David, which version of the compiler did generate the MVC instructions? was this with or without the INITAUTO option? We use the z/OS v1.6 version, and this version only generates the MVI, not the MVCs. We will not use INITAUTO due to serious performance degradation. At the moment, management discusses the strategy to follow: a) opening a PMR with IBM, and, if IBM agrees and changes their compilers, recompiling all our C programs b) accepting the behaviour of the IBM C compilers and examining all our sources, changing all partial structure initializations to memset and, again, recompiling all our C programs Kind regards Bernd David Crayford schrieb: Are you sure there isn't an MVC after the MVI? I rely on that kind of initialization all the time and have never had a problem. A quick test program shows the correct behavior. If this is not working as the ANSI standard I suggest you open a PMR. To circumvent the problem compile with INITAUTO(0). * * struct F * { * int a; * char string[20];* short s;* }; * *struct F f = {0}; LA r0,0 ST r0,f.F.a(,r4,2016) MVI f(r4,2020),0 MVC f(23,r4,2021),f(r4,2020) Compiled with CHECKOUT compiler option generates the following message. INFORMATIONAL CCN3447 DOC.C(F1):14The member(s) starting from string will be initialized with a default value of 0. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Bernd, I'm using z/OS V1.10 without INITAUTO. We've compiled our code all the way back to OS/390 2.8 and I can't recall ever seeing this problem. I'm sure it's a codegen bug, otherwise what is the point of the MVI? I wouldn't accept anything other than a fix from IBM. Although your compiler is out of support! Quote 6.7.8.21 of the ANSI C standard which clearly states: If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. Bernd Oppolzer wrote: Hello David, which version of the compiler did generate the MVC instructions? was this with or without the INITAUTO option? We use the z/OS v1.6 version, and this version only generates the MVI, not the MVCs. We will not use INITAUTO due to serious performance degradation. At the moment, management discusses the strategy to follow: a) opening a PMR with IBM, and, if IBM agrees and changes their compilers, recompiling all our C programs b) accepting the behaviour of the IBM C compilers and examining all our sources, changing all partial structure initializations to memset and, again, recompiling all our C programs Kind regards Bernd David Crayford schrieb: Are you sure there isn't an MVC after the MVI? I rely on that kind of initialization all the time and have never had a problem. A quick test program shows the correct behavior. If this is not working as the ANSI standard I suggest you open a PMR. To circumvent the problem compile with INITAUTO(0). * * struct F * { * int a; * char string[20];* short s;* }; * *struct F f = {0}; LA r0,0 ST r0,f.F.a(,r4,2016) MVI f(r4,2020),0 MVC f(23,r4,2021),f(r4,2020) Compiled with CHECKOUT compiler option generates the following message. INFORMATIONAL CCN3447 DOC.C(F1):14The member(s) starting from string will be initialized with a default value of 0. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Hi Bernd We had several PMR's about the C++ compiler and the compiler team reacted always very fast and competently (maybe as they are in Canada ;-) ) On 5/19/2010 9:21 AM, Bernd Oppolzer wrote: Hello David, which version of the compiler did generate the MVC instructions? was this with or without the INITAUTO option? We use the z/OS v1.6 version, and this version only generates the MVI, not the MVCs. We will not use INITAUTO due to serious performance degradation. At the moment, management discusses the strategy to follow: a) opening a PMR with IBM, and, if IBM agrees and changes their compilers, recompiling all our C programs b) accepting the behaviour of the IBM C compilers and examining all our sources, changing all partial structure initializations to memset and, again, recompiling all our C programs Kind regards Bernd David Crayford schrieb: Are you sure there isn't an MVC after the MVI? I rely on that kind of initialization all the time and have never had a problem. A quick test program shows the correct behavior. If this is not working as the ANSI standard I suggest you open a PMR. To circumvent the problem compile with INITAUTO(0). * * struct F * { * int a; * char string[20];* short s;* }; * *struct F f = {0}; LA r0,0 ST r0,f.F.a(,r4,2016) MVI f(r4,2020),0 MVC f(23,r4,2021),f(r4,2020) Compiled with CHECKOUT compiler option generates the following message. INFORMATIONAL CCN3447 DOC.C(F1):14The member(s) starting from string will be initialized with a default value of 0. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Hi Again Bernd, That psuedo-assembler appears to be initializing a 5-bytes of storage. Are you sure the 'scp1215ein' data type is 24 bytes? Can you show the typedef for 'scp1215ein'? Does there happen to be any packing going on? Bitfields, etc... - Dave Rivers - Bernd Oppolzer wrote: Sorry for the missing line feeds. C statement: *scp1215ein in1215 = { 0 }; Pseudo ASSEMBLER (structure starts at 272(r13)): STr6,a5:d272:l4(,r13,272) MVI a5:d276:l1(r13,276),0 C statement: *scp1215aus out1215= { 0 }; Pseudo ASSEMBLER (structure starts at 296(r13)): STr6,a5:d296:l4(,r13,296) MVI a5:d300:l1(r13,300),0 Kind regards Bernd Bernd Oppolzer schrieb: To make it clear: see above The ST operations initialize the first components of the structures, which are fullwords. This is what should be done, according to the IBM C language reference. The rest of the structures should remain unchanged (uninitialized), according to IBM's language reference, and should be set to zero, according to ANSI C language reference. The structure out1215, for example, is 24 bytes long. Now the MVI makes absolutely no sense to me. It would only make some sense, if it was followed by an overlapped MVC instruction, which would set the rest of the structure to zero. But such a instruction is not generated by the compiler. ??? Kind regards Bernd Bernd Oppolzer schrieb: Hello all, sorry for asking this question on IBM-Main, but the C370 list is so silent that I doubt that anyone is actually listening. We observed a sort of problem today which showed up as a 0C4 abend due to a not proper initialized pointer component of a C structure. Further examination showed that the structured was initialized as follows structure_type structure_identified = { 0 }; The structure has several components; the last component is the pointer. According to the IBM C language reference, only the first component is initialized to zero, and the other components have random contents, because the storage class is automatic. The compiler generates only initialization logic for the first few bytes of the auto structure. So from this point of view, everything is right. But: the ANSI C language reference, for example in the Kernighan Ritchie book appendix, and most other C language references I found on the web, clearly state that if the number of initializers on structure initialization is less than the number of structure components, the remaining components are initialized to zero, even for auto structures. This is not an error in that sense that the compiler does not what is written in the language reference, but instead it is a contradiction between IBM's language reference and ANSI language reference. What do you think about this? Does it make sense to complain at IBM about it? We have hundreds of C programs in production use which use this kind of initialization (maybe) and now we are afraid that we need to examine all these programs. Kind regards -- riv...@dignus.comWork: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Bernd Oppolzer wrote: Hello David, which version of the compiler did generate the MVC instructions? was this with or without the INITAUTO option? We use the z/OS v1.6 version, and this version only generates the MVI, not the MVCs. We will not use INITAUTO due to serious performance degradation. At the moment, management discusses the strategy to follow: a) opening a PMR with IBM, and, if IBM agrees and changes their compilers, recompiling all our C programs b) accepting the behaviour of the IBM C compilers and examining all our sources, changing all partial structure initializations to memset and, again, recompiling all our C programs I'm pretty confident the IBM compiler follows the ANSI C standard and that some other reason is the cause of the confusion. If you discover it doesn't, and it's a problem; might I humbly offer our alternative (which can operate in your LE environment.) We definately would initialize that structure to all zeros. And, if you're recompiling anyway... might as well give our compiler a try... Just a (partially shameless) plug. - Dave Rivers - -- riv...@dignus.comWork: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
-Original Message- From: IBM Mainframe Discussion List [mailto:ibm-m...@bama.ua.edu] On Behalf Of Bernd Oppolzer Sent: Tuesday, May 18, 2010 2:14 PM To: IBM-MAIN@bama.ua.edu Subject: partially initialized structures in C (3) Sorry for the missing line feeds. C statement: *scp1215ein in1215 = { 0 }; Pseudo ASSEMBLER (structure starts at 272(r13)): STr6,a5:d272:l4(,r13,272) MVI a5:d276:l1(r13,276),0 C statement: *scp1215aus out1215= { 0 }; Pseudo ASSEMBLER (structure starts at 296(r13)): STr6,a5:d296:l4(,r13,296) MVI a5:d300:l1(r13,300),0 Kind regards Bernd Just me (and I'm not really good with C), but why not just use memset()? memset(in1215,0,sizeof in1215); -- John McKown Systems Engineer IV IT Administrative Services Group HealthMarkets(r) 9151 Boulevard 26 * N. Richland Hills * TX 76010 (817) 255-3225 phone * (817)-961-6183 cell john.mck...@healthmarkets.com * www.HealthMarkets.com Confidentiality Notice: This e-mail message may contain confidential or proprietary information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. HealthMarkets(r) is the brand name for products underwritten and issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life Insurance Company of TennesseeSM and The MEGA Life and Health Insurance Company.SM -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Are you sure there isn't an MVC after the MVI? I rely on that kind of initialization all the time and have never had a problem. A quick test program shows the correct behavior. If this is not working as the ANSI standard I suggest you open a PMR. To circumvent the problem compile with INITAUTO(0). * *struct F *{ * int a; * char string[20]; * short s; *}; * *struct F f = {0}; LA r0,0 ST r0,f.F.a(,r4,2016) MVI f(r4,2020),0 MVC f(23,r4,2021),f(r4,2020) Compiled with CHECKOUT compiler option generates the following message. INFORMATIONAL CCN3447 DOC.C(F1):14The member(s) starting from string will be initialized with a default value of 0. Bernd Oppolzer wrote: Sorry for the missing line feeds. C statement: *scp1215ein in1215 = { 0 }; Pseudo ASSEMBLER (structure starts at 272(r13)): STr6,a5:d272:l4(,r13,272) MVI a5:d276:l1(r13,276),0 C statement: *scp1215aus out1215= { 0 }; Pseudo ASSEMBLER (structure starts at 296(r13)): STr6,a5:d296:l4(,r13,296) MVI a5:d300:l1(r13,300),0 Kind regards Bernd Bernd Oppolzer schrieb: To make it clear: see above The ST operations initialize the first components of the structures, which are fullwords. This is what should be done, according to the IBM C language reference. The rest of the structures should remain unchanged (uninitialized), according to IBM's language reference, and should be set to zero, according to ANSI C language reference. The structure out1215, for example, is 24 bytes long. Now the MVI makes absolutely no sense to me. It would only make some sense, if it was followed by an overlapped MVC instruction, which would set the rest of the structure to zero. But such a instruction is not generated by the compiler. ??? Kind regards Bernd Bernd Oppolzer schrieb: Hello all, sorry for asking this question on IBM-Main, but the C370 list is so silent that I doubt that anyone is actually listening. We observed a sort of problem today which showed up as a 0C4 abend due to a not proper initialized pointer component of a C structure. Further examination showed that the structured was initialized as follows structure_type structure_identified = { 0 }; The structure has several components; the last component is the pointer. According to the IBM C language reference, only the first component is initialized to zero, and the other components have random contents, because the storage class is automatic. The compiler generates only initialization logic for the first few bytes of the auto structure. So from this point of view, everything is right. But: the ANSI C language reference, for example in the Kernighan Ritchie book appendix, and most other C language references I found on the web, clearly state that if the number of initializers on structure initialization is less than the number of structure components, the remaining components are initialized to zero, even for auto structures. This is not an error in that sense that the compiler does not what is written in the language reference, but instead it is a contradiction between IBM's language reference and ANSI language reference. What do you think about this? Does it make sense to complain at IBM about it? We have hundreds of C programs in production use which use this kind of initialization (maybe) and now we are afraid that we need to examine all these programs. Kind regards Bernd -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: partially initialized structures in C (3)
Now the MVI makes absolutely no sense to me. It makes the string initialized to the null string (), no? Charles -Original Message- From: IBM Mainframe Discussion List [mailto:ibm-m...@bama.ua.edu] On Behalf Of Bernd Oppolzer Sent: Tuesday, May 18, 2010 12:14 PM To: IBM-MAIN@bama.ua.edu Subject: partially initialized structures in C (3) Sorry for the missing line feeds. C statement: *scp1215ein in1215 = { 0 }; Pseudo ASSEMBLER (structure starts at 272(r13)): STr6,a5:d272:l4(,r13,272) MVI a5:d276:l1(r13,276),0 C statement: *scp1215aus out1215= { 0 }; Pseudo ASSEMBLER (structure starts at 296(r13)): STr6,a5:d296:l4(,r13,296) MVI a5:d300:l1(r13,300),0 Kind regards Bernd Bernd Oppolzer schrieb: To make it clear: see above The ST operations initialize the first components of the structures, which are fullwords. This is what should be done, according to the IBM C language reference. The rest of the structures should remain unchanged (uninitialized), according to IBM's language reference, and should be set to zero, according to ANSI C language reference. The structure out1215, for example, is 24 bytes long. Now the MVI makes absolutely no sense to me. It would only make some sense, if it was followed by an overlapped MVC instruction, which would set the rest of the structure to zero. But such a instruction is not generated by the compiler. ??? Kind regards Bernd Bernd Oppolzer schrieb: Hello all, sorry for asking this question on IBM-Main, but the C370 list is so silent that I doubt that anyone is actually listening. We observed a sort of problem today which showed up as a 0C4 abend due to a not proper initialized pointer component of a C structure. Further examination showed that the structured was initialized as follows structure_type structure_identified = { 0 }; The structure has several components; the last component is the pointer. According to the IBM C language reference, only the first component is initialized to zero, and the other components have random contents, because the storage class is automatic. The compiler generates only initialization logic for the first few bytes of the auto structure. So from this point of view, everything is right. But: the ANSI C language reference, for example in the Kernighan Ritchie book appendix, and most other C language references I found on the web, clearly state that if the number of initializers on structure initialization is less than the number of structure components, the remaining components are initialized to zero, even for auto structures. This is not an error in that sense that the compiler does not what is written in the language reference, but instead it is a contradiction between IBM's language reference and ANSI language reference. What do you think about this? Does it make sense to complain at IBM about it? We have hundreds of C programs in production use which use this kind of initialization (maybe) and now we are afraid that we need to examine all these programs. Kind regards Bernd -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html