First, I seem to be getting responses from thoughtful individuals who
want to tell me how to avoid the core. That's not the point. I want
the core. I need the core.
Secondly, everyone wants to comment on my use of p = 0;, advising me
that I would be better off using p = 0L;. The C FAQ is quite clear on
this matter.
1.1 What is this infamous null pointer, anyway?
. . .
A null pointer is conceptually different from an uninitialized pointer.
A null pointer is known not to point to any object; an uninitialized
pointer might point anywhere. See also questions 3.1, 3.13, and 17.1.
. . .
References: K&R I Sec. 5.4 pp. 97-8; K&R II Sec. 5.4 p. 102; H&S Sec.
5.3 p. 91; ANSI Sec. 3.2.2.3 p. 38.
1.2 How do I "get" a null pointer in my programs?
According to the language definition, a constant 0 in a pointer context
is converted into a null pointer at compile time. That is, in an
initialization, assignment, or comparison when one side is a variable or
expression of pointer type, the compiler can tell that a constant 0 on
the other side requests a null pointer, and generate the correctly-typed
null pointer value. Therefore, the following fragments are perfectly
legal:
char *p = 0;
if(p != 0)
. . .
References: K&R I Sec. A7.7 p. 190, Sec. A7.14 p. 192; K&R II Sec. A7.10
p. 207, Sec. A7.17 p. 209; H&S Sec. 4.6.3 p. 72; ANSI Sec. 3.2.2.3 .
Now that it is painfully clear that the program is correct as designed
let me re-ask my original question in more detail.
When compiling "cc -g foo.c -o foo" and running foo, the core file size
on AIX 3.2.5 is appx 19kb. When compiling "cc -g foo.c -o foo" and
running foo the core file size is appx 5Mb on HPUX 10.20.
So, since it is obvious that AIX is creating a partial core (the system
ulimits have been checked), how do I force AIX to create a full core.
dlm
> How can I get the operating system to provide a full core for the
> following program?
> int main()
> {
> long i = 0;
> char * p = 0;
> long a[1000000];
> char *cp;
> cp = (char*)malloc(1000000);
> for(i = 1; i < 1000000; i++)
> {
> a[i] = i;
> *cp = 0x41;
> }
> *p = 1;
> return 0;
> }
> The core file is always 26k even though I touched both the array and the
> char*.