0

Unknown keywords in C

I have been using C for about a week now and I was wondering what ‘static’ and ‘pub’ are?

25th Sep 2025, 11:39 AM
leo
leo - avatar
3 odpowiedzi
+ 1
it's a great question! static: depends on the context, but has two possible usage. static variable: keeps its value between function calls static function: also known as global variable pub: not exists in c, it exists in rust I hope this helps
25th Sep 2025, 6:08 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
Hello leo! I am assuming, by the provided information, that ypu are beginner in C. It is great to see your interest and willingness to learn deeply! To begin with, static is a real keyword in C while pub does not exist. As,Mihaly Nyilas already explained, startic depends on context. At file scope i.e. outside of functions, declaring a global variable/function as static,limits its visibility to the file in which it is defined and other translation units cannot access it (via extern). This is because it now has internal linkage. You can read more here: https://www.w3schools.com/c/ref_keyword_static.php https://www.geeksforgeeks.org/c/internal-linkage-external-linkage-c/ If used inside a function, i.e. local scope, a static local variable is initialised only once and retains its value between function calls, unlike normal local variables which are created and destroyed each time the function is called. More: https://www.geeksforgeeks.org/c/static-variables-in-c/
27th Sep 2025, 1:37 AM
Ushasi Bhattacharya
0
That said, leo , I take this opportunity to further let you know that pub is not a real C keyword. You may have seen pub in Rust, where it means "public". I Rust, it is used for visibility control as it makes a module, function, struct, or other item visible and accessible from outside its current module or scope. More: https://doc.rust-lang.org/std/keyword.pub.html https://doc.rust-lang.org/reference/visibility-and-privacy.html https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch07-02-controlling-visibility-with-pub.html
27th Sep 2025, 1:42 AM
Ushasi Bhattacharya