[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: casting an 'int' to a class
From: Charles Samuels <charles () kde ! org>
Date: 2002-01-22 2:57:12
[Download RAW message or body]
On Monday 21 January 2002 04:54 pm, Ellis Whitehead wrote:
> Would the following cast from an int to a struct cause problems on any
> systems?
>
> struct A {
> int a;
> int x();
> };
>
> int foo() {
> int b = 0;
> return ((A*)(&b))->x();
> }
Eeewwww :)
>
> I have a couple classes related to kdelibs/kdecore/kkey* that contain only
> a single 'int' of data. I would like to keep them private and put 'int's
> in the containing class definition.
1) remove the &
2) I *think* some platforms (sparc64?) have sizeof(int) != sizeof(void*)
Of course, if sizeof(int) and sizeof(void*) were the same, and the variable is
private, you should be able to just change the type.
>
> Thanks,
> Ellis
>
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> >> unsubscribe <<
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic