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 242,829 of 243,242    |
|    David Brown to Michael Sanders    |
|    Re: function pointer question    |
|    06 Jan 26 15:55:37    |
      From: david.brown@hesbynett.no              On 06/01/2026 13:32, Michael Sanders wrote:       > On Mon, 5 Jan 2026 08:39:53 -0000 (UTC), Michael Sanders wrote:       >       >> I might have questions down the road...       >       > One more question, but 1st the context...       >       > I asked ChatGPT this question:       >       > In C, what is the most common meaning of (void) *foo       >       > Its reply:       >       > In C, (void) *foo most commonly means:       >       > “Evaluate *foo, but explicitly discard its value.”       >       > It is a cast-to-void used to silence warnings about an       > unused expression or unused result.       >       > My question: Why?       >              It is not uncommon for people to have "-Wunused" warnings enabled in       their builds. If you have declared variables in a function, and       possibly assigned values to them, but don't read them or use them,       that's likely a mistake in your code. The compiler can eliminate the       unused variables and associated calculations, but a warning can remind       you that your function is perhaps not finished yet. Similarly, warnings       on unused parameters can be helpful if you have forgotten something.              But sometimes you know you don't need the variables or parameters, but       you might still want to have the declarations there. Maybe they are       used with some builds with different conditional compilation, or you       know you might need them later. Maybe you have extra parameters because       the function has to fit a particular set of parameter types, even though       in some cases you don't need them all. (In C23, you can leave a       parameter unnamed in the definition - but not prior to C23.)              As a way to silence such warnings - or as an indication to human readers       that you know you don't need the value - you can cast the value to void.              It can also be used for discarding values from a function return marked       "[[nodiscard]]" in C23 (or using equivalent compiler-specific features       prior to C23), or after reading a volatile variable when you want the       read to be done, but don't care about the value.              --- 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