Original Post
🔒 Locked
[C] static types?
Advertisement
In C the keyword "static" modifies the variable instance not the variable type.
Preserves variable value to survive after its scope ends.
If you want to hide a type from other translation units, don't put the definition of that type inside any header that you include in other translation units. If you want to limit that type definition to a single translation unit, declare it in the ".c" file of that unit, at the top of the file or at least before the point where it's used. Avoid using that type as an argument to any function that you want to export from that translation unit.
Preserves variable value to survive after its scope ends.
If you want to hide a type from other translation units, don't put the definition of that type inside any header that you include in other translation units. If you want to limit that type definition to a single translation unit, declare it in the ".c" file of that unit, at the top of the file or at least before the point where it's used. Avoid using that type as an argument to any function that you want to export from that translation unit.
Quote:
Original post by LessBread
Preserves variable value to survive after its scope ends.
static applied to a global variable has a different meaning: it gives the variable internal linkage.
[Edited by - SiCrane on October 24, 2009 5:04:42 PM]
struct node{ struct node *next; int size;};#define HEAP_SIZE 1000static struct node heap[HEAP_SIZE];As I understand it, static objects are zero-initialized in C*. Does that mean that heap.next will be the null pointer, or will it be sizeof(struct node*) zero bytes? Will (heap.next == 0) yield 1 or 0?
*Yes I know, globals are always static, even without the static :-) I just don't want heap to escape the translation unit.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement