* casting int to / from pointer on alpha
@ 1997-10-30 13:10 Bryan B. Thompson
1997-10-30 15:20 ` Michal Jaegermann
0 siblings, 1 reply; 3+ messages in thread
From: Bryan B. Thompson @ 1997-10-30 13:10 UTC (permalink / raw)
Hello,
I am porting an application with some X11 interface code that was originally
ported years back from SunView, so its definately got a "legacy". There are
some instances in the code where XtCallbackProc instances are used and the
old code assumed that one of the parameters, properly a pointer, could swallow
an 'int' and not burp. Well, its burping.
I do not understand how the alpha handles explicit (or implicit) int/void*
casts. Is it doing sign extension? Preserving the lower 32 bits?
What I would like to find is an appropriate incantation for casting an int
to/from a pointer that will work on the alpha, and elsewhere as well. Can
this be done in general, or must I make sure that the 'int' in question is
typed as a 'long' on the alpha so that it happily can co-exist in the space
of a pointer.
This is all C programming, of course. I'm sorry if this is too off target
for this list, but I though some people out there could answer this one from
experience and the answer seems of general interest in porting (bad) code to
the alpha.
Thanks,
-- bryan thompson
Cognitive Technologies, Inc.
bryan@cog-tech.com
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: casting int to / from pointer on alpha
1997-10-30 13:10 casting int to / from pointer on alpha Bryan B. Thompson
@ 1997-10-30 15:20 ` Michal Jaegermann
0 siblings, 0 replies; 3+ messages in thread
From: Michal Jaegermann @ 1997-10-30 15:20 UTC (permalink / raw)
>
> There are
> some instances in the code where XtCallbackProc instances are used and the
> old code assumed that one of the parameters, properly a pointer, could swallow
> an 'int' and not burp. Well, its burping.
A pointer can swallow an int, although without a cast will raise
objections and deservedly though. Although a function expecting
a pointer and which got an int will cause a misalignment of your stack.
Casting the other way around may be deadly. If a pointer was really
an address and not a "generic container" then you will loose half
of it.
> I do not understand how the alpha handles explicit (or implicit) int/void*
> casts. Is it doing sign extension? Preserving the lower 32 bits?
If you have doubts then writing a three line program which prints values
in question before and after will tell you the story right away.
Also printings sizeof(a_type_in_question_here) can be informative. :-)
> What I would like to find is an appropriate incantation for casting an int
> to/from a pointer that will work on the alpha, and elsewhere as well.
In general this will never work. Sometimes you can cheat. For a
portable code overlaying types a 'union' construct was invented. I know
that there is a lot of code which does not bother because "this happens
to work here". Bummer!
> Can
> this be done in general, or must I make sure that the 'int' in question is
> typed as a 'long' on the alpha so that it happily can co-exist in the space
> of a pointer.
Pointers are unsigned quantities. You can cast int to a pointer
explicitely. Making ints into longs is, in general, a terrible idea.
Once again - watch out what you are passing to functions. Religiously
supplying prototypes helps a lot.
Michal
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: casting int to / from pointer on alpha
[not found] <199710301520.IAA09122@ellpspace.math.ualberta.ca>
@ 1997-10-30 17:57 ` Richard Henderson
0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 1997-10-30 17:57 UTC (permalink / raw)
On Thu, Oct 30, 1997 at 08:20:51AM -0700, Michal Jaegermann wrote:
> A pointer can swallow an int, although without a cast will raise
> objections and deservedly though. Although a function expecting
> a pointer and which got an int will cause a misalignment of your stack.
No it won't. All arguments are padded to 64-bits; 32-bit integer
values are sign extended.
r~
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-10-30 17:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-10-30 13:10 casting int to / from pointer on alpha Bryan B. Thompson
1997-10-30 15:20 ` Michal Jaegermann
[not found] <199710301520.IAA09122@ellpspace.math.ualberta.ca>
1997-10-30 17:57 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox