Re: Detect direction of stack growth
From: xarax (xarax_at_email.com)
Date: 12/27/04
- Next message: Dave Thompson: "Re: Is there a library function for placing cursor position in the cosole?"
- Previous message: Chris Torek: "Re: Language efficiency of C versus FORTRAN et al"
- In reply to: Adam Warner: "Re: Detect direction of stack growth"
- Next in thread: Keith Thompson: "Re: Detect direction of stack growth"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Dec 2004 04:18:10 GMT
"Adam Warner" <usenet@consulting.net.nz> wrote in message
news:pan.2004.12.27.03.00.17.959974@consulting.net.nz...
> Hi Keith Thompson,
>
> > Adam Warner <usenet@consulting.net.nz> writes:
> >> Is this a (C99) portable way to detect whether the C stack grows
> >> upwards (1) or downwards (-1)?
> >
> > No. There is no portable way to do this. Applying a relational
> > operator to addresses of distinct objects (objects that are not
> > contained in some larger composite object) invokes undefined behavior.
>
> Can I cast the addresses of the objects on the stack to uint64_t
> (7.18.1.1) and use a relational operator upon those values? This type
> is defined for all conforming implementations with 64 bit integers.
You cannot get any meaningful information. Stack management
is implementation dependent. Some implementations grow down,
some grow up, some are segmented, some grow in either direction.
Forget about it.
> What practically portable method exists to perform pointer arithmetic via
> integers?
Pointer arithmetic is only meaningful for addresses within a single object.
> Does one first perform an implementation-specific check upon the
> size of the address space?
A meaningless question.
> Can I practically rely upon the address space
> never being larger than 64 bits?
No. That presumes a linear address space. An address space
need not be linear. IBM mainframe architecture has non-linear
virtual spaces with 64-bit "addresses" and 25-bit "space designation".
Somewhat like trying to compare two complex numbers for greater-than
or less-than; non-sensical. Only equals or unequals has meaning when
comparing two objects that may not be the same object.
- Next message: Dave Thompson: "Re: Is there a library function for placing cursor position in the cosole?"
- Previous message: Chris Torek: "Re: Language efficiency of C versus FORTRAN et al"
- In reply to: Adam Warner: "Re: Detect direction of stack growth"
- Next in thread: Keith Thompson: "Re: Detect direction of stack growth"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|