If you use the COBOL - C API routines this program will work.
GnuCOBOL supports many of the same routines defined by Microfocus...
I changed your test case as follows:
#define COBCALL 1
int main()
{
cobchar_t *argv[2];
argv[0] = (void *)(0x1111111111111111);
argv[1] = (void *)(0x2222222222222222);
cob_init(0,NULL);
#ifdef COBCALL
cobcall ("routine1",2,argv);
#else
routine1((void *)(0x1111111111111111),(void *)(0x2222222222222222));
#endif
return 0;
}
void one_parameter(void *dummy)
{
cobchar_t *argv[2];
argv[0] = (void *)(0x3333333333333333);
argv[1] = (void *)(0x4444444444444444);
// Uncomment the next line to make the problem go away:
// cob_get_global_ptr ()->cob_call_params = 2;
#ifdef COBCALL
cobcall ("routine2",2,argv);
#else
routine2((void *)(0x3333333333333333),(void *)(0x4444444444444444));
#endif
}
And then the output is as expected.
cobc -x main.c routine1.cbl routine2.cbl
./main
Arrived at routine1
This should be '0x1111111111111111' and is 0x1111111111111111
This should be '0x2222222222222222' and is 0x2222222222222222
Arrived at routine2
This should be '0x3333333333333333' and is 0x3333333333333333
This should be '0x4444444444444444' but is 0x4444444444444444
Leaving routine2
Leaving routine1