strange - restriction with CLR (.NET)?

W

Walter H.

Hi,

the following code snippet ...

const int nEnvLnCnt = 11;

System::String* strEnvVars[ ] = { S"ComSpec", S"Path", S"Prompt",
S"HomeDrive", S"HomePath", S"LogonServer", S"SystemDrive",
S"SystemRoot", S"UserDomain", S"UserProfile", S"UserName" };

System::String* strEnvLines[ ] = new System::String* [ nEnvLnCnt ];

for ( int iter = 0; iter < nEnvLnCnt; iter++ )
strEnvLines[ iter ] = System::String::Format( S"{0}={1}",
strEnvVars[ iter ], System::Environment::GetEnvironmentVariable(
strEnvVars[ iter ] ) );


this compiles without any errors or warnings but

System::String* strEnvVars[ nEnvLnCnt ] = { /* the same as above */ };

doesn't compile, why?



file.cpp(370) : error C3616: '11': a size cannot be specified in a __gc
array declaration
file.cpp(370) : error C3184: 'System::String __gc *strEnvVars
__gc[,,,,,,,,,,]' : initialization of multi-dimensional arrays via an
initializer list is not supported
file.cpp(370) : error C2440: '=' : cannot convert from 'System::String
__gc * __gc[]' to 'System::String __gc * __gc[,,,,,,,,,,]'
Cannot convert between __gc arrays of different ranks
file.cpp(370) : error C3262: invalid array indexing: 1 dimension(s)
specified for 11-dimensional 'System::String __gc * __gc[,,,,,,,,,,]'
....
 
W

Walter H.

Paavo said:
[email protected]:

Hi,

the following code snippet ...

const int nEnvLnCnt = 11;

System::String* strEnvVars[ ] = { S"ComSpec", S"Path", S"Prompt",
S"HomeDrive", S"HomePath", S"LogonServer", S"SystemDrive",
S"SystemRoot", S"UserDomain", S"UserProfile", S"UserName" };

System::String* strEnvLines[ ] = new System::String* [ nEnvLnCnt ];

for ( int iter = 0; iter < nEnvLnCnt; iter++ )
strEnvLines[ iter ] = System::String::Format( S"{0}={1}",
strEnvVars[ iter ], System::Environment::GetEnvironmentVariable(
strEnvVars[ iter ] ) );


this compiles without any errors or warnings but

System::String* strEnvVars[ nEnvLnCnt ] = { /* the same as above */ };

doesn't compile, why?


Wrong group. The above is not C++. You will need to find a group with CLR
or .NET in the name I guess.

Cheers
Paavo

Wrong answer ...

This is C++ for .NET

Greetings,
Walter
 
W

Walter H.

Paavo said:
Paavo said:
[email protected]:



Hi,

the following code snippet ...

const int nEnvLnCnt = 11;

System::String* strEnvVars[ ] = { S"ComSpec", S"Path", S"Prompt",
S"HomeDrive", S"HomePath", S"LogonServer", S"SystemDrive",
S"SystemRoot", S"UserDomain", S"UserProfile", S"UserName" };

System::String* strEnvLines[ ] = new System::String* [ nEnvLnCnt ];

for ( int iter = 0; iter < nEnvLnCnt; iter++ )
strEnvLines[ iter ] = System::String::Format( S"{0}={1}",
strEnvVars[ iter ], System::Environment::GetEnvironmentVariable(
strEnvVars[ iter ] ) );


this compiles without any errors or warnings but

System::String* strEnvVars[ nEnvLnCnt ] = { /* the same as above */
};

doesn't compile, why?


Wrong group. The above is not C++. You will need to find a group with
CLR or .NET in the name I guess.

Cheers
Paavo

Wrong answer ...

This is C++ for .NET


If you read the message "===Welcome to comp.lang.c++! Read this first."
which is regularly posted in this group then you find:

"First of all, please keep in mind that comp.lang.c++ is a group for
discussion of general issues of the C++ programming language, as defined
by the ANSI/ISO language standard."

The aforementioned standard is ISO/IEC 14882. The "C++ for .NET"
(whatever you mean by that, I think there are at least two separate
candidates which might qualify) is not covered by this standard and the
question you asked most probably is specific to that language, so I doubt
you will get any "right" answers in this group.

Cheers
Paavo

wrong answer again; don't say "this" and mean "that"; which group do you
mean?
 
M

m0shbear

Hi,

the following code snippet ...

const int nEnvLnCnt = 11;

System::String* strEnvVars[ ] = { S"ComSpec", S"Path", S"Prompt",
   S"HomeDrive", S"HomePath", S"LogonServer", S"SystemDrive",
   S"SystemRoot", S"UserDomain", S"UserProfile", S"UserName" };

System::String* strEnvLines[ ] = new System::String* [ nEnvLnCnt ];

for ( int iter = 0; iter < nEnvLnCnt; iter++ )
   strEnvLines[ iter ] = System::String::Format( S"{0}={1}",
     strEnvVars[ iter ], System::Environment::GetEnvironmentVariable(
       strEnvVars[ iter ] ) );

this compiles without any errors or warnings but

System::String* strEnvVars[ nEnvLnCnt ] = { /* the same as above */ };

doesn't compile, why?

..Net,CLI,etc. is _Microsoft_ C++. comp.lang.c++ is _standard_ C++.
comp.os.ms-windows.programmer is where you should post if you want
results.
 
J

jacob navia

Le 19/03/11 18:03, Walter H. a écrit :
Hi,

the following code snippet ...

const int nEnvLnCnt = 11;

System::String* strEnvVars[ ] = { S"ComSpec", S"Path", S"Prompt",
S"HomeDrive", S"HomePath", S"LogonServer", S"SystemDrive",
S"SystemRoot", S"UserDomain", S"UserProfile", S"UserName" };

System::String* strEnvLines[ ] = new System::String* [ nEnvLnCnt ];

for ( int iter = 0; iter < nEnvLnCnt; iter++ )
strEnvLines[ iter ] = System::String::Format( S"{0}={1}",
strEnvVars[ iter ], System::Environment::GetEnvironmentVariable(
strEnvVars[ iter ] ) );


this compiles without any errors or warnings but

System::String* strEnvVars[ nEnvLnCnt ] = { /* the same as above */ };

doesn't compile, why?



file.cpp(370) : error C3616: '11': a size cannot be specified in a __gc
array declaration

Without knowing anything about C++ .NET, I can still READ. The error
message is very clear:

'11': a size cannot be specified in a __gc array declaration

The compiler tells you that you can't specify a size in a __gc
declared array, for whatever reasons, probably because arrays so
declared are dynamic arrays or whatever.

And now you arrive at the number one rule of programming:

When the compiler writes an error message: READ IT.

This rule has fallen into the bit bucket probably because people got
used to incomprehensible error messages in C++.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top