error: parameter may not have variably modified type

J

Johannes Schaub (litb)

Helmut said:
Johannes said:
James said:
On Oct 22, 8:31 am, Helmut Jarausch <[email protected]>
wrote:
Victor Bazarov wrote:
Helmut Jarausch wrote:
Victor Bazarov wrote:
...
Can anybody throw some light on this error?
We can. And to help us help you you should start by
reading the FAQ, especially the section 5.
Here is a small but complete example to show the problem.
See the last 4 lines.
[..valid code redacted..]
Comeau online trial compiles your code without a problem.
Obviously there is something wrong with the compiler you are
using. Try contacting the maker of it, upgrade it,
downgrade it, or/and even post to the newsgroup dedicated to
that compiler.
I've created a bug report for gnu.gcc and the answer was
I don't think this is misparsing this at all. This is one
place in the C++ standard that says it should be parsed as a
function declaration rather than a variable declaration to
resolve an ambiguous between those two.
So, who is right? Whom to ask next?
In a certain sense, it doesn't matter. The authors of g++ are
more or less gods when it comes to their compiler, and if they
decide on one particular interpretation, and you have to use
g++, you're stuck with it, even if it doesn't make sense or is
manifestly wrong.

And if it's a function declaration, indeed, how to tell the
compiler that I wish a variable declaration?
Here the questionable code again (see the last few lines, first)
[...]
form proj (space(V), V_new_i, "mass");
/* error: parameter may not have variably modified type
'space [(((long unsigned int)(((long int)i) + -0x00000000000000001))
+ 1)]'
*/
First, there is absolutely no way that proj can be interpreted
as a function declaration; the string literal prevents that,
regardless of anything else. Second, if "space" is the
name of a type (as it is in your code), »space(V)« is a
function declaration in any context that allows function
declarations.


This further depends on "V" being a type. If it's a non-type name,
"space(V)" is an array declaration with redundant parens. If V is a
type, it's a function declaration.


How can that be? AFAIK, a function declaration has the form

<Type> <Name>( <Type> <Name>,...)

Even if 'V' is type name, how are the square brackets interpreted in that
case?

Sorry for the double post. Here are some examples of matching code:

typedef int V;
typedef int space;

// means: void f(space param(V param)) { }
void f(space(V)) { }

If V is not a type, it's going to be

void f(space V) { }

Hope that makes sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top