Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mach_port_t



Hi Peter,

On Aug 1, 2005, at 8:01 AM, Peter Seebach wrote:

Some Apple code includes lines like:

    mach_port_t masterPort = NULL;

When I compile this, I get a warning about converting a pointer to an integer
without a cast.

Yes, this is expected on gcc 4.0. Earlier versions of gcc did not flag this. 

The main thing that changed is that the C standard now defines NULL as (void *) 0. Earlier versions of the language did not specify a value for NULL and most implementations defined NULL as 0.

Converting a pointer to an integer is legal but non-portable: the result is implementation-defined.


Sure enough, mach_port_t is an unsigned int.  In fact, most of the things
used like this seem to be unsigned ints, which are only passed around as
cookies returned by mach calls.

So.

Why are they always initialized as though they were pointers?

You'd have to ask the authors of the code. :-) My guess is that NULL was just convenient. More strictly correct would be MACH_PORT_NULL. Tiger also introduced IO_OBJECT_NULL as ((io_object_t) 0).

Tiger was built (mostly) with gcc 3.3. As Mac OS X moves to being built with gcc 4.0, I would expect these warnings to be cleaned up.

In the I/O Kit master port case, since Jaguar there's been the constant kIOMasterPortDefault. Just pass that to any call that needs the I/O Kit master port, and you no longer need to call IOMasterPort() explicitly.

-s

--gc

__________________________________________________________________

Garth Cummings                                   1 Infinite Loop, MS 303-2T

Apple Developer Technical Support       Cupertino, CA 95014

                               

"The last good thing written in C was    408-974-7711 phone

Franz Schubert's Symphony No. 9."       408-862-7602 fax

--Erwin Dieterich                                  email@hidden



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

References: 
 >mach_port_t (From: email@hidden (Peter Seebach))



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.