Pages

June 06, 2010

     dumpHexa(&x, sizeof x);
putchar('\n');

return 0;
}

/* Dump the first n bytes to the address a */
void dumpHexa(void *a, int n) {
int i;
unsigned char *c = (unsigned char *)a;

for (i = 0; i < n; i++)
printf("%02x ", c[i]);
}
------------------------------------------------------------------

Synonym Pointer Types

Synonym pointer types simplify pointer definitions.

For example, let us define a synonym for a pointer to an int


 typedef int * Pint;

We can then define several pointer variables without having to include the * before each identifier

Pint px, py;

Note that this is more readable than the alternative primitive definition

int* px,* py;
------------------------------------------------------
IEEE 754
1,8,23 or 1,23,8 for double, long .
1.52,11 or 1,11,52 for long long.

Local Duration

A function parameter or a variable that is defined within a block has local extent unless otherwise specified. Its lifetime lasts from its definition until the closing brace of the block that contains that definition.

There are two distinct usages of local types:

  • normal
  • very frequent

For normal usage, we may add the keyword auto (for automatic) to the definition


 auto int local = 2;

Since this is the default for any function parameter or any variable defined within a block, we seldom see this keyword in practice.

For very frequent usage, we add the keyword register to the definition


 register int local = 2;

This keyword informs the compiler that the local variable should, if possible, remain in a CPU register as long as necessary. However, since the number of registers is extremely limited, the compiler might not implement such a request.


Internal Linkage

A variable of static duration with internal linkage is invisible outside its own module. To identify internal linkage, we add the keyword static to the definition


 static int local = 2;
/* Internal Linkage
* static.c
* May 12 2007
*/

#include

void display() {
static int local = 0;

printf("local is %d\n", local++);
}

int main(void) {

display();
display();

return 0;
}

local is 0
local is 1

No comments:

Post a Comment