Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="David Brown, post: 5152243"] I missed that bit - sometimes threads in c.l.c. get so long that I have to skip many details. But you are right - that /is/ a good reason to have unnamed parameters in C. If you have to fit a function into a particular general function type, then you will sometimes be forced to have parameters that are never used, and typically have generic names like "param1" in the function type declaration - leaving them unnamed in the function definition would be clear documentation that they are never used in that particular function. So I'll make a minor U-turn and say that unnamed parameters in C /would/ sometimes be a useful feature. True, but without any standard way of handling this then "(void) x;" is the simplest and clearest way to have a statement with no effect. I think the idea is perhaps unusual - and it is certainly heretic in c.l.c. If you haven't done embedded development, then the idea of "disabling interrupts" is probably a bit odd. But let's take another example. Suppose you have some sort of lock, with two functions "getBigLock()" and "releaseBigLock()": extern void getBigLock(void); extern void releaseBigLock(void); // Don't call this unless you've got the big lock! extern void doSomethingDangerous(void); void foo(void) { getBigLock(); doSomethingDangerous(); releaseBigLock(); } void bar(void) { doSomethingDangerous(); } In this case, the compiler cannot help spot that bar() is going to cause trouble - you are reliant on comments and programmer care to get the locking right. In C++, you could do this: class BigLock { public: BigLock() { getBigLock(); } ~BigLock() { releaseBigLock(); } } extern void doSomethingDangerous(const BigLock&); void foo(void) { BigLock bl; doSomethingDangerous(bl); } void bar(void) { doSomethingDangerous(); } bar() is now clearly a compile-time error. doSomethingDangerous() doesn't actually do anything with the parameter - it just uses type-checking to ensure that you have a BigLock. With enough care, templates, and hierarchies, you can do quite a bit of compile-time checking using types like this. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
Top