Welcome, Guest. Please login or register.

Author Topic: OpenDevice (C help needed please!)  (Read 2324 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: OpenDevice (C help needed please!)
« on: November 02, 2003, 10:19:00 AM »
Basically what you're doing is telling the compiler to temporarily override its stong type checking. Normally, if you declare a variable in a function 'int', but then pass an 'unsigned long' to it, you'll get an error (or a warning at the very least) informing you there's a type mismatch. The problem here is that OpenDevice(), being a very general function to deal with any device, only accepts general IORequest structures. But in your program, you're dealing with SerialIORequests, AudioIORequests, SCSIIORequests, and what not. Passing such a structure to OpenDevice() would cause the compiler to flag an error, so you tell it: 'Look, right this moment, this SerialIORequest has type IORequest. Trust me, I know what I'm doing, so quit complaining.' You could even cast it to void *, or char * or somesuperblynewflashytype * if you wanted (and the function was defined with that type, otherwise you'll still get a type mismatch error).

As iamaboringperson said, you'd do well to start reading a book on ANSI-C. Get the (expensive but) definitive guide by Kernighan and Ritchie, 2nd edition. Worth every last penny.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.