Apple Enterprise - NeXTanswers Support Archive
Enterprise
[Index]
[Download]


Search NeXTanswers for:

Q: I am trying to perform a method that returns a float. In the Concepts manual, page 3-20, it indicates I can just cast the return value to float like this:

float myGray;
myGray = (float)[textField perform:@selector(backgroundGray)];

But I get a compile-time error of "pointer value used where a float was expected." What can I do?

A: The perform method is prototyped to return a value of type id. While the C compiler lets you cast of lot of things, it says enough is enough when you try cast something of type id to be float. Here is one workaround which allows you to get the value you want:

id myId;
float myGray;
myId = [textField perform:@selector(backgroundGray)];
myFloat = *(float *)&myId;

Valid for 1.0, 2.0, 3.0

QA557



OpenStep | Alliances | Training | Tech Support | Where to Buy