Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   strange - restriction with CLR (.NET)? (http://www.velocityreviews.com/forums/t745408-strange-restriction-with-clr-net.html)

Walter H. 03-19-2011 05:03 PM

strange - restriction with CLR (.NET)?
 
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[,,,,,,,,,,]'
....

Walter H. 03-19-2011 06:40 PM

Re: strange - restriction with CLR (.NET)?
 
Paavo Helde wrote:
> "Walter H." <Walter.H-Nntp@mathemainzel.info> wrote in news:4d84e1ca$0$1585
> $91cee783@newsreader04.highway.telekom.at:
>
>
>>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

Walter H. 03-19-2011 08:28 PM

Re: strange - restriction with CLR (.NET)?
 
Paavo Helde wrote:

> "Walter H." <Walter.H-Nntp@mathemainzel.info> wrote in
> news:4d84f8b0$0$1583$91cee783@newsreader04.highway .telekom.at:
>
>
>>Paavo Helde wrote:
>>
>>>"Walter H." <Walter.H-Nntp@mathemainzel.info> wrote in
>>>news:4d84e1ca$0$1585 $91cee783@newsreader04.highway.telekom.at:
>>>
>>>
>>>
>>>>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?

m0shbear 03-19-2011 09:56 PM

Re: strange - restriction with CLR (.NET)?
 
On Mar 19, 1:03*pm, "Walter H." <Walter.H-N...@mathemainzel.info>
wrote:
> 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.

jacob navia 03-19-2011 11:18 PM

Re: strange - restriction with CLR (.NET)?
 
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++.


All times are GMT. The time now is 07:35 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.