Re: Diffs between OpenBSD 3.9 gcc 3.3.5 <-> Linux 2.6 gcc 4.0 ?



BobH, thanks for your advice but I regret to say that I've already
tried both of those with much the same results. :-(

Your advice on not counting on the compiler passing a pointer for
arrays is well-taken, but for gcc it should be consistent. Besides, it
works fine in other places in the same program, plus it works on little
test programs such as the one below, which seems to work fine and
identically in OpenBSD and Linux.

This seems to be a fundamental problem, but I'm stumped.

Jim

/*
% cc -g -O0 -o mem mem.c
*/

/*
* Test passing of addr to a big array.
*/

#include <stdio.h>

/* Convenience typedefs */
typedef unsigned char UINT8;
typedef char SINT8;
typedef unsigned short UINT16;
typedef short SINT16;
typedef unsigned int UINT32;
typedef int SINT32;
typedef unsigned long UINT64;
typedef long SINT64;

typedef float FLOAT32;
typedef double FLOAT64;

#define SZ 1000488
#define ZERO 0
#define ONE 1

int main(SINT32 argc, UINT8 **argv) {
UINT8 bigarr[SZ];
SINT32 ij;

printf("main: &bigarr %x size %d\n",
&bigarr[0], sizeof(bigarr));

ij = ONE;
for (ij = 0; ij < sizeof(bigarr); ij++) {
bigarr[ij] = ij & 0xFF;
}

sub(bigarr, sizeof(bigarr));

printf("Done\n");

}

sub(UINT8 *mybig, SINT32 mybigsiz) {
SINT32 kk = ZERO;
UINT8 *myname = "sub";

printf("%s: addr mybig %x size %d\n",
myname, mybig, mybigsiz);

kk = ONE;
printf("%s: mybig from 0 to %d:\n", myname, 8 * 16);
for (kk = 0; kk < 8 * 16; kk++) {
printf("%2x ", mybig[kk] & 0xff);
if(kk > 0 && (kk % 16 == 0)) {
printf("\n");
}
}
printf("\n");

printf("%s: mybig from %d to %d:\n",
myname, mybigsiz - 8 * 16 - 1, mybigsiz - 1);
for (kk = mybigsiz - 8 * 16 - 1; kk < mybigsiz; kk++) {
printf("%2x ", mybig[kk] & 0xff);
if(kk > 0 && (kk % 16 == 0)) {
printf("\n");
}
}
printf("\n");
}

BobH wrote:

Hi,
I have had mixed luck assuming that function calls passing arrays
actually pass as a pointer. I think that is a compiler dependent
feature, but it may have been codified by one of the later ansii revisions.

I would try:
err = buildReqExeMsg(&packed[0], sizeof(packed),
&sessEKey[0], &sessHKey[0],
&padKey[0], reqexelen,
&exefile[0], exefileLen,
&packedLen);

Another idea would be to make sure the large arrays are declared in
global space, so that they don't wind up on the stack.

Good Luck,
Bob

.



Relevant Pages

  • Re: [C] functions and 2D arrays?
    ... >>This works, and I like the idea of using typedef, but to solidify ... 'int ' for every instance of 'foo bar' in the code. ... to arrays of arrays of int, when you could be passing pointers ...
    (alt.comp.lang.learn.c-cpp)
  • Re: size of a typedef with arrays of unsigned char
    ... arrays of unsigned char, the sum of the size of the arrays? ... The reference to typedef is irrelevant. ... in a record consisting of arbitrary byte-sized chunks, ...
    (comp.lang.c)
  • Re: Returning structs containing arrays
    ... > of ints and an int. ... contains two pointers and an integer. ... arrays if you initialize them to point to allocated memory. ... The typedef "arrays" doesn't name a structure type; ...
    (comp.lang.c)
  • Re: TIP #129 and 64 Bit platforms
    ... > What I need are integer types, that are the same size on all ... "at-least-32-bits" and long long (or a typedef if I have to support ... for byte arrays, so I never need exact-sized types. ...
    (comp.lang.tcl)
  • Re: "Portability" contructs like UINT32 etc.
    ... >> I often see advice elsewhere, and in other peoples programs, ... >> typedef char CHAR; ... >> typedef int INT32; ...
    (comp.lang.c)