× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



A warning, for those who use ALIGN on an RPG DS to get the RPG DS
defined equivalently to a C struct.

The C compiler always creates the struct with trailing filler space, so
that the size of the struct is an exact multiple of the alignment.  RPG
does not do this.

For the following C struct, sizeof(s) = 8.
   struct s
   {
      int i;
      char a;
   };

For this apparently matching RPG data structure, %SIZE(s) = 5, not 8.
   D s          DS          align
   D   i             10i 0 
   D   a              1a

If you code DIM(1) on the DS, %SIZE(s1) = 5, but %size(s1:*all) = 8. 
The RPG compiler would allocate 8 bytes for the DIM(1) DS.
   D s1         DS          align dim(1)
   D   i             10i 0 
   D   a              1a

If you are defining an RPG data structure to match a C struct, check the
cross reference to make sure it is an exact multiple of the alignment
size (16 if there is a pointer; 8 if there is an 8-byte integer or
double float; 4 if there is a 4-byte integer or float; 2 if there is a
2-byte integer).

Or write a little C program to get the size of the C struct and make
sure the RPG XREF shows the same length (you can use the "length" entry
on the DS line to get the RPG size correct, or you can add a filler
subfield at the end).

#include <regex.h>
#include <stdio.h>
main()
{
   printf ("%d\n", sizeof(regex_t));
}

Note that this isn't an RPG bug, it's just a difference between C and
RPG.  RPG's ALIGN keyword isn't defined to make the RPG data structure
the same as a C data structure, although it pretty much has that effect
other than in this instance.  (But I know that it _would_ be nice if RPG
had an easy way to define a DS whose size was an exact multiple of its
alignment.)


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.