Παρασκευή, 9 Μαρτίου 2012

NSLog - Tokens - %@ - %p memory token, %zu size_T token (tip to find the type (32 or 64 bit) of environment)

in NSLog the first argument is required and must be an NSString instance.
This instance is called the format string and it contains text and a number of tokens.
The tokens (also called format specifications) are prefixed with a percent (%) symbol.

  • With the %@ is encountered in the format string, instead of the token being replaced by the corresponding argument, that argument is sent the message description. The description method returns an NSString that replaces the token. Every object implements the method description.
  • With the %p token you can see the memory address of a variable or functions name!.

    %@ Object, calls the Object's description method
    %d, %i signed int
    %u unsigned int
    %f float/double
    %p for pointers to show the memory address
    %zu value of type size_t (for sizeof(variable function)
    %s C strings
    \u can used for arbitrary unicode chars example:NSLog(@"\u03c0");//π



------------------------------
Variables:
int i =17;
printf("i stores the value at the address %p\n", &i);

i stores its value at 0xbfffb749

Function name
printf("the main function starts at %p", main);


  • With the %zu you can return a value of type size_t (for sizeof(variable) function)

printF("A pointer is %zu bytes", sizeof(int *));
4 bytes long pointer = 32 bit mode
8 bytes long pointer = 64 bit mode



  • With the \u you can use arbitrary unicode chars 
NSLog (@"\u03c0"); // π 

Last edit: 19/5/2012
Last edit: 21/4/2012
Last edit: 22/3/2012

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου