about:blank , black holes or grep "${rootpswrd}" /etc/passwd .0 (zero) for most basic ( primitive ) types and as NULL exclusively for pointers.In fact, in the context of pointers, bothNULLand0applicable, since the first is nothing more than a macro wrapper for the second:#define NULL ((void *)0)
However, you should not useNULLas a replacement for0in those places where zero is an algebraic value:int c = b*a; if (c != NULL) { printf("Neither b nor a is equal to 0\n"); }
nil . nil is a pointer to a null object: #if !defined(nil) #define nil (id)0 #endif NULL .NSNull class, which has a single (not counting inherited) method +null which returns a singleton of class NSNull .Nil (not to be confused with nil ) - a null pointer of type Class : #if !defined(Nil) #define Nil (Class)0 #endif Nil in real life is hard to come up with: only a few NSString , with the name NSArray (yes, this is not something else, as explained below) in runtime: #inlcude <objc/runtime.h> Class foo = objc_allocateClassPair([NSString class], "NSArray", 0); /* NSArray , Nil — */ if (Nil != foo) { int check = class_addMethod(foo, @selector(makeWorldBetter), (IMP)_makeWorldBetter, "v@:")); if (check) objc_registerClassPair(foo); } nilnil :-capitalizedStringWithLocale: method of the NSString class takes a locale (an object of the NSLocale class) as an argument, or nil — in the latter case, when changing the case of a string, the canonical decomposition (NFD) of Unicode characters is used regardless of the locale settings on the user's computer (that is, this method will be equivalent to the method -capitalizedString ). - (NSDictionary*)dictionaryForLicenseFile:(NSString *)path { NSData *licenseFile = [NSData dataWithContentsOfFile:path]; /* «, !» */ if (!licenseFile) return nil; return [self dictionaryForLicenseData:licenseFile]; } It should be noted, by the way, that the practice of ivars initialization common to developers with zero values in the methods of the-init*family-init*not make sense , since their values were already equal to zero even in the-allocmethod:... memory for all other instance variables is set to 0.
nil ) in Objective-C is the ability to send him absolutely any messages, the answer to which will always be the same nil : id foo = nil; int zero = [foo bar: @"Hello, Habr!"]; /* In a galaxy far, far away… */ if (foo != nil && [foo testValue: 0x90]) { … } /* */ if ([foo testValue: 0x310403]) { … } Some novice developers, having learned about this feature ofnil, transfer it to non-zero objects, forgetting to check whether the called method exists in this class, and inevitably catch exceptions ( exception ) if it is not:/* « NSPersistentStoreCoordinator» © Brad Cox & Tom Love */ NSData *signature = [NSString stringWithFormat: @"%lu", 0xCAFEBABE]; /* — @catch : -bytes NSString */ bytes = [signature bytes];And it would have been okay if only novice developers were doing it ...A few months ago, I discovered a similar bug in The Tagger’s application license verification system, this bug allowed any user (and not just someone who can work with a file ) to bypass the restriction of the trial version by simply slipping an invalid.licfile (or more precisely.ttl) to the.ttl.
It goes without saying that I notified the developer about this, but I never received an answer.
By the way, the Cocoa version of the popular class AquaticPrime (which, as a rule, developers prefer the CoreFoundation version) was responsible for the verification code.
nil equality: many of your methods from standard frameworks, and (I bet) some of your own, are simply not designed to work with “zero” objects. Take at least +[NSArray arrayWithObjects:] - try to create an array of three objects with nil at the top of the list and look at the result. Another example: +[NSString stringWithString:] , by calling which with nil as an argument, get an exception.NSNull : nothing or something?nil values.NSNull is a kind of wrapper over NULL and nil, allowing you to store them in Objective-C collection objects.
{ "keys": ["X"], "command": "set_action_motion", "args": { "action": "vi_left_delete", "motion": null }, "context": [{"key": "setting.command_mode", "modes": [] }] } args["motion"] is nothing , that is, null ! This value will be read into an object of the NSNull class as a result of the parser operation.| Designation | Flick of the wrist ... | Poslenie |
|---|---|---|
| 0 | 0 | Zero - he is zero everywhere |
| Null | (void *) 0 | C pointer zero |
| nil | (id) 0 | Null pointer to an Objective-C object |
| Nil | (Class) 0 | Zero pointer of type Class in Objective-C |
| NSNull | [NSNull null] | Singleton class NSNull - wrappers over nil and Null |
Source: https://habr.com/ru/post/165021/
All Articles