C/C++ issues
The code I'm trying to port (UNIX->Windows) is an extreme fan of this convention:
Visual Studio flips out and cries when this happens; the very same code compiled happily in GCC under Cygwin. I saw something somewhere that declaring functions inside other functions is strictly forbidden in C; is this true? Does GCC waive this little restriction? Is there anything else I can do about this than make the function and the variable global? I suppose I could make a struct that has those variables within it, add that as an argument to otherfunction and everything else that's ever aware of it, but that sounds like a royal pain. Is there a setting somewhere that makes this possible again?
click
void function() { int variable, othervariable; int otherfunction(arguments) { doStuff(arguments); doDifferentStuff(variable, othervariable); return result; } doSomethingElse(otherfunction); }
Visual Studio flips out and cries when this happens; the very same code compiled happily in GCC under Cygwin. I saw something somewhere that declaring functions inside other functions is strictly forbidden in C; is this true? Does GCC waive this little restriction? Is there anything else I can do about this than make the function and the variable global? I suppose I could make a struct that has those variables within it, add that as an argument to otherfunction and everything else that's ever aware of it, but that sounds like a royal pain. Is there a setting somewhere that makes this possible again?
click
no subject
I've not seen that convention before. I suppose it's supposed to be a bit like anonymous functions, and the original author wishes he were working in SML or Lisp or something. Personally I'd just move the inner function out and make it a normal global function. Unless, of course, there's some reason that the code is like that which I can't discern without context and/or content.
no subject
no subject
no subject
This sounds odd but in C# at least some things compile from the command line that don't compile from within the product, even using the same compiler. I think the GUI has weird flags turned on by default. I'm not talking about warnings, I've seen inconsistent errors between the two methods.
Not that it helps you but it may make you feel better about thinking VS is on crack.
no subject
Still, it's not good C{++}, so I'd globalize (probably as a private) that inner function as a helper, and go from there.
Of course, if you're writing in an ML or LISP variant, or Python (and presumably many others) this is good style, and actually works quite well.
no subject
I'd probably convert it so that doSomethingElse takes an additional argument (or more) which is passed to otherFunction when it is called. (E.g., a void * argument.) Or, there are some crazy things that C++ can do with templates and classes...