| Author |  Topic  |  | 
              
                | coder0xffStarting Member
 
 
 
                1 Posts | 
                    
                      |  Posted - Mar 17 2005 :  3:53:36 PM   
 |  
                      | When I declare a __gc array : 
 System::Drawing::Bitmap* conditionalLayers __gc[];
 
 VA X doesn't seem to consider this a declaration, and underlines 'conditionalLayers' in red.  It doesn't appear in the suggestion list. If I remove the '__gc[]' it is fine.
 |  
                      | [email protected]
 ---------------------
 "Two things are infinite: the universe and human stupidity; and Im not sure about the universe. -- Albert Einstein"
 |  | 
              
                | felineWhole Tomato Software
 
      
 
                United Kingdom19247 Posts
 | 
                    
                      |  Posted - Mar 20 2005 :  5:04:26 PM   
 |  
                      | this looks like it could be managed C++ code, going by the namespace usage. 
 what is this line doing?  i have learned some C# so i know a small amount about .NET programming.  however i don't recognise what this code is doing.
 
 i am not finding any reference to "conditionalLayers" in the .NET documentation.
 |  
                      | zen is the art of being at one with the two'ness
 |  
                      |  |  | 
              
                | jpizziTomato Guru
 
      
 
                USA642 Posts
 | 
                    
                      |  Posted - Mar 20 2005 :  7:02:12 PM   
 |  
                      | conditionalLayers is his variable name. __gc[] is a garbage collected array. Can't tell if this is C# or managed C++, though. |  
                      | Joe Pizzi
 |  
                      |  |  | 
              
                | jorgito11Senior Member
 
    
 
                USA29 Posts
 | 
                    
                      |  Posted - Mar 21 2005 :  3:56:20 PM   
 |  
                      | The code is managed C++ (MC++). coder0xff is creating a managed array. A managed array has two types (in this case, Bitmap and the Array types). "StringBuilder* sb[] = new StringBuilder*[3];" and "StringBuilder* sb __gc[] = __gc new StringBuilder*[3];" are essentially the same except the intellisense does not recognize the second one. Either "__gc" can be removed without causing a compiling error. 
 However, since types such as "int" that can be interpreted as a __value type or unmanaged POD, you are forced to use __gc:
 
 int i __gc[] = {1, 2, 3}; // Intellisense is confused!
 
 However, this is okay:
 
 Int32 i[] = {1, 2, 3}; // Intellisense is working here!
 
 since "Int32" is only a __value type.
 
 Most MC++ programmers will use "int" before using "Int32"!
 
 |  
                      | Edited by - jorgito11 on Mar 21 2005  3:58:15 PM
 |  
                      |  |  | 
              
                | felineWhole Tomato Software
 
      
 
                United Kingdom19247 Posts
 | 
                    
                      |  Posted - Mar 21 2005 :  5:00:28 PM   
 |  
                      | interesting.  obviously there is a lot more to the basic types in .NET than i had realised. 
 case=534
 
 experimenting with this i am getting errors when i try the line:
 
 
 String *testArray __gc[]; 
 in C#, while it compiles quite happily in managed C++.  does this mean this idea only applies to managed C++?
 |  
                      | zen is the art of being at one with the two'ness
 |  
                      |  |  | 
              
                | jorgito11Senior Member
 
    
 
                USA29 Posts
 | 
                    
                      |  Posted - Mar 24 2005 :  11:55:40 AM   
 |  
                      | Yes, this only applies to Managed C++ because MC++ can have managed and unmanaged code living together. The code, 
 String *testArray[], has an implied __gc before the "[]" because the type is managed. However, CString *strArray[] has no implied __gc since the type is definitely unmanaged. However, int i[] is ambiguous since it can be a managed array of Int32 __value types or an unmanaged array of POD integers. The C# compiler and itellisense does not have to worry about this difference since everything is managed.
 
 C++/CLI in VS.NET 2005 has a new syntax to address this since it is very confusing for the developer to sort out what is managed and unmanaged.
 |  
                      | Edited by - jorgito11 on Apr 01 2005  11:57:37 AM
 |  
                      |  |  | 
              
                | felineWhole Tomato Software
 
      
 
                United Kingdom19247 Posts
 | 
                    
                      |  Posted - Mar 28 2005 :  2:24:48 PM   
 |  
                      | *ah* i now recall reading an article about the new syntax for pointers in .NET 2005 for managed C++, but i had not started learning C# at the time i read it, and it made very little sense.  now it makes a lot more sense, thank you for the explanation  |  
                      | zen is the art of being at one with the two'ness
 |  
                      |  |  | 
              
                |  |  Topic  |  |