Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

static in C

Name: Richard 2010-12-22 7:35

Hi. (:

I'm a C# programmer who recently had to write some C code. I found out that C has the static keywoard but C doesn't have classes so it can't do the same thing static does in C#. Please explain static in C to me.

Name: Anonymous 2010-12-22 10:48

>>5
Because the designers of C++ had a goal of introducing as few new keyword as possible, to maintain as much compatibility with C code as possible (which includes not only compiling C code as C++ code with minor changes, but also easily calling C functions (which may happen to be named with a new keyword)).

The `static` keyword already means two different things in C: on the module level it means that the decorated object (a variable or a function) would not be exported, inside a function body it means that its value persists between invocations (as if it was declared outside the function, but not visible from anywhere other than this function).

C++ gave it a third meaning: in the class definition context it means that the decorated object belongs to a class and has class lifetime (which is a kind of similar to the second meaning, in a weird way).

Then C# got rid of the first two meanings, so there's no intersection between C and C# meanings.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List