2025-07-19 16:53 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002745AIAIpublic2011-11-24 23:06
ReporterAF 
Assigned Tohoijui 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
Summary0002745: VS2010/C90 incompatibility in C++ AI Wrapper in ::GetCustomParams() functions
Descriptionconst char* keys[_size];
const char* values[_size];
_ret_int = bridged__UnitDef_getCustomParams(this->GetSkirmishAIId(), this->GetUnitDefId(), keys, values);

Here the Visual Studio compiler cannot statically initialize the keys and values arrays ( wait the parameter is a const char** not a const char* could this not be clearer? ).

What's more the semantics of this call do not follow const correctness, since the end result is a modification of a constant value ( constants aren't supposed to change )
Additional InformationThis code I've modified DOES compile:

const char* keys = new char[_size];
const char* values = new char[_size];

_ret_int = bridged__UnitDef_getCustomParams(this->GetSkirmishAIId(), this->GetUnitDefId(), &keys, &values);

Changes like this in a handful of other places makes Shard build under VS2010
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0007651

AF (reporter)

Note Shard isnt building, this just reduces the number of errors

~0007657

hoijui (reporter)

Last edited: 2011-11-23 11:02

the code does follow const correctness. it are two arrays of constant strings. he arrays are not constant, but the strings are. nothing bad there (of course this would not compile on GCC, if it were incorrect).
your code creates memory leak. ;-)
but yeah, will change it.
the root of the problem is that VS does only support C90, not C99 standard (have a guess how old that standard is already ;-) ).

thanks for the report :-)

~0007661

hoijui (reporter)

.. your code would also crash at runtime, as you have arrays of chars, instead of arrays of strings.

~0007662

AF (reporter)

I never said my code worked, I just said it compiled =p How exactly it's fixed correctly is your call, though that function and those like it are all useless anyway and do nothing appreciable even if they did work as they're incomplete.

~0007692

hoijui (reporter)

i already fixed this function locally, including what was missing (content of the for loop).
little use lies in the debate, true.

~0007693

hoijui (reporter)

resolved by:
https://github.com/spring/spring/commit/7043612ddcc2e32122ca32991be148fa4fac2e3f
+Notes

-Issue History
Date Modified Username Field Change
2011-11-22 22:19 AF New Issue
2011-11-22 22:39 AF Note Added: 0007651
2011-11-23 10:59 hoijui Status new => assigned
2011-11-23 10:59 hoijui Assigned To => hoijui
2011-11-23 11:02 hoijui Note Added: 0007657
2011-11-23 11:02 hoijui Note Edited: 0007657
2011-11-23 11:03 hoijui Severity block => major
2011-11-23 21:15 hoijui Note Added: 0007661
2011-11-23 21:23 AF Note Added: 0007662
2011-11-24 21:56 hoijui Note Added: 0007692
2011-11-24 22:33 hoijui Summary VS2010 AI issue and Const correctness IN ::GetCustomParams() functions => VS2010/C90 incompatibility in C++ AI Wrapper in ::GetCustomParams() functions
2011-11-24 23:06 hoijui Note Added: 0007693
2011-11-24 23:06 hoijui Status assigned => resolved
2011-11-24 23:06 hoijui Resolution open => fixed
+Issue History