top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

VLA parameters not accepted by g++?

0 votes
380 views

Reading the gcc 5.1 manual it seems that VLA parameters must be accepted by g++. For example the following is fine when compiled with gcc --std=gnu11

float sum (int M, float x[M]) {
 return x[0] + x[1];
}

int main (void) {
 float xs[2] = {1, 2};
 float acc = sum (2, xs);
 return 0;
}

But it is rejected by g++ --std=gnu++11. Is this possible at all with g++?

posted Jun 28, 2015 by Alok Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

No, I don't think so, G++ only supports some kinds of VLA.

You have to use float x[] or float* x in C++.

answer Jun 28, 2015 by Sanketi Garg
Similar Questions
0 votes

This code compiles on MSVC but not on G++ :

template
class B
{
public:
 static void SomeMethod()
 {
 A::SomeMethod();
 }
};

class A
{
public:
 static void SomeMethod();
};

void test()
{
 B::SomeMethod();
}

The error with g++ is :

test.cpp: In static member function "static void B::SomeMethod()":
test.cpp:7:3: error: "A" has not been declared

Is there is a option to indicate to g++ to evaluate the template functions only when a specialization is called, and not before ?

–1 vote

I have a c++ shared object that I am compiling using the following command.
g++ -g -Wall -c -o cpplib.o cpplib.cpp

And I am creating the shared object using the following command.
g++ -shared -o libcpplib.so cpplib.o

(I am aware that I can do this one single command, these are two separate invocations because I had the project setup on eclipse and that's how eclipse cdt does it.).

My host runs a RedHat 6.x x86_64 OS.

The compilation fails with the following error.

$ g++ -g -Wall -fPIC -c -o cpplib.o cpplib.cpp
$ g++ -shared -fPIC -o libcpplib.so cpplib.o
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libstdc++.a(ios_init.o): relocation R_X86_64_32 against `pthread_cancel' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/libstdc++.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

I am certain that I haven't used the 'pthread_cancel' function in my code. Please help me.

0 votes

I'm not a c++/template guru and i can't decide if this is really a valid code or i have encountered a gcc bug:

template  struct A {
 void *p;
};
template  struct B : A {
 void *foo() { return p; }
};

g++ says "error: 'p' was not declared in this scope". microsoft's compiler is happy with the same code.

Can anyone help?

+5 votes

GCC is stripping the object file when nothing from the file is being used anywhere in the executable (even -o0 does nor help). We have to disable this feature of linker g++. could any one please help us to resolve this issue??

+1 vote

If I compile c++ code, I am supposed to use g++. This automatically does some magic that calling just Gcc would not do. The same with Fortran code and gfortran. So my question is which frontend should I use to link if I have object files from both c++ as well as Fortran, c, and maybe another language still?

...