Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 241,956 of 243,242    |
|    Richard Harnden to Kenny McCormack    |
|    Re: Attributes on functions/variables (s    |
|    14 Nov 25 17:31:14    |
   
   From: richard.nospam@gmail.invalid   
      
   On 14/11/2025 14:20, Kenny McCormack wrote:   
   > Wow! An actual on-topic C question. Don't see much of that around here   
   > these days...   
   >   
   > My question has to do specifically with "static" - as seen below - but also   
   > in general with these sorts of attributes of functions and variables.   
   >   
   > Suppose I have code like this:   
   >   
   > /* static */ char *foo(int);   
   > int somefun(...) { code that uses foo() }   
   > ...   
   >   
   > static char *foo(int bar) { definition of foo() }   
      
   I don't think I've ever had a non-static function prototype early in my   
   code, then it being used, and then it's static defininition later.   
      
   I've always had the static definition just before it's used and no   
   prototype, static or not, at all. Dunno if that's normal, or just the   
   style I learnt.   
      
   >   
   > Is foo() static or not? Does the order matter? Suppose the first reference   
   > to foo() had static and the second one didn't?   
   nm should lable exported functions as 'T', and static functions as 't'   
   ... I don't know if that helps you.   
      
   >   
   > Or is it a syntax error to have different declarations/definitions like   
   > this? What if they occur (as they usually will do) in different files (TUs)   
   ?   
      
   static would make it private to the TU.   
      
   If you remove that and there are multiple foos in different TUs, then   
   it's easy to imagine how things could get confused - to the point that   
   it'll refuse to link.   
      
   >   
   > Note that this came up in real life - I had to change a function that had   
   > been static to non-static and was concerned about what would happen if I   
   > didn't change it in every place. I didn't do much testing and decided to   
   > post here instead.   
   >   
   Probably you need to wait for a followup from someone who knows what   
   they're talking about :)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca