Very Simple Compile failing on Solaris 10

I'm on a Solaris 10 box.
The compiler I'm using is: /opt/solstudio12.2/bin/CC

Compiling the file shown below (myTest2.C) fails.

% CC -I. -o myTest2 myTest2.C
"myTest2.C", line 30: Error: "{" expected instead of "myFunc".
"myTest2.C", line 33: Error: "{" expected instead of "myFunc".
2 Error(s) detected.

Why is it an error to call myFunc() while declaring a variable?
How to get around it?

----------------------------------------------------------------------------
#include <iostream>
#include <string>



using namespace std;


char* myFunc(string inString)
{
char outString[1024];
int i;
for (i = 0; i <= inString.size()-1; i++)
outString[i] = inString[i];
outString[i+1] = '\0';
return outString;
}





extern "C" {
}

// This Works:
static char myVariable1 [ ] = "MyString1" ;

// This Breaks:
static char myVariable2 [ ] = myFunc("MyString2") ; // Line #30

// This Breaks:
char myVariable5 [1024] = myFunc("MyString3"); // Line
#33





int main()
{
// This Works:
string Z = myFunc("Gdkkn Vnqkc");
cout << "Z = " << Z << endl << endl;

}
closed account (DSLq5Di1)
There is quite a few problems with that code..
http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope
Topic archived. No new replies allowed.