[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: casting an 'int' to a class
From:       Frerich Raabe <frerichraabe () gmx ! de>
Date:       2002-01-22 4:56:57
[Download RAW message or body]

On Tuesday, 22. January 2002 01:54, 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();
> }
>
> 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.

I'm just guessing from what I've been able to figure out so far, but I think 
such evil casts indicate a design flaw. Right now you can break binary 
compatibility to resolve such stuff, perhaps it's worth a try. Such code as 
the above is IMHO way too fragile to be used anywhere else but in testcases.

- Frerich
 
>> 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