• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Function definitions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function definitions


  • Subject: Re: Function definitions
  • From: Ondra Cada <email@hidden>
  • Date: Sun, 9 Apr 2006 03:05:21 +0200

Alan,

On 9.4.2006, at 2:34, Alan Hart wrote:

If the .h file didn't exist you'd have to build the whole of your application in one file, or #include the whole of that .c file in every other .c file that wants to call sum(), and then every file in your project would get recompiled any time you changed one line in sum(). And you'd get tied up in knots working out which file was #including which.

Quite the contrary. See please my answer to Robert.

Wonderful! So why do I get compiler errors every time I miss a #include or #import?

Whilst function/message declarations are not needed, generally you cannot do without macros, inlines, and global variable declarations (which includes classes).


Also, without being able to cast properly the compiler fails on struct arguments/returns (since unknown functions return/use ints, unknown messages return/use ids, neither of which is castable to/from structs). For similar reason, floats would compile (with a warning), but fail runtime.

That aside, you get lotta warnings, since the compiler knows the dangers too :)

Nevertheless, the code actually can do without declarations, if you name classes explicitly and dodge all macros and similar things (note using "0" instead of "nil" below; note we have to dodge even @"..." static strings; also note that the warnings--of which there would be a swarm--are thrown to null):

19 /tmp> <q.m
#define S(s) [objc_getClass("NSString") stringWithCString:s]
int main() {
[objc_getClass("NSAutoreleasePool") new];
id a=[NSClassFromString(S("NSArray")) arrayWithObjects:S("this"),S ("is"),S("somewhat"),S("weird"),0];
NSLog(S("Whoa! %@"),[a componentsJoinedByString:S(" * ")]);
return 0;
}
20 /tmp> cc q.m -framework Cocoa 2>/dev/null && ./a.out
2006-04-09 03:01:56.838 a.out[710] Whoa! this * is * somewhat * weird
21 /tmp>


Whilst perhaps interesting from the understandig-how-things-work POV, this has hardly any practical consequence: just do use declarations (and write ones for your own code). All the time :)
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Function definitions (From: Jonathan <email@hidden>)
 >Re: Function definitions (From: Alan Hart <email@hidden>)
 >Re: Function definitions (From: Ondra Cada <email@hidden>)
 >Re: Function definitions (From: Alan Hart <email@hidden>)

  • Prev by Date: Re: Function definitions
  • Next by Date: Re: Cocoa bindings performance
  • Previous by thread: Re: Function definitions
  • Next by thread: Moderator EOT (Re: Function definitions)
  • Index(es):
    • Date
    • Thread