G
Guest
I found a bug??? with constants in csharp. Consider the following:
internal static readonly int MAX_BUFFER_SIZE=8192;
internal static readonly int
MAX_MESSAGE_LENGTH=MAX_BUFFER_SIZE-USER_DATA_OFFSET;
internal static readonly int USER_DATA_OFFSET=29;
When the constant MAX_MESSAGE_LENGTH is calculated the USER_DATA_OFFSET
is 0 at this stage and the result is 8192 rather than 8192-29 as
expected.
Now I know the order of static variables is undetermined across
different class files. But (and I really can't remember cos I haven't
done C/C++ for years) I thought this was calculated corrected in C/C++.
If this is not the case then csharp should flag the 2nd line as an
error if it doesn't know what USER_DATA_OFFSET is. Better than leaving
it as 0 and letting it compile without problems. Now I need to verify
that all constants are used after they are declared.
internal static readonly int MAX_BUFFER_SIZE=8192;
internal static readonly int
MAX_MESSAGE_LENGTH=MAX_BUFFER_SIZE-USER_DATA_OFFSET;
internal static readonly int USER_DATA_OFFSET=29;
When the constant MAX_MESSAGE_LENGTH is calculated the USER_DATA_OFFSET
is 0 at this stage and the result is 8192 rather than 8192-29 as
expected.
Now I know the order of static variables is undetermined across
different class files. But (and I really can't remember cos I haven't
done C/C++ for years) I thought this was calculated corrected in C/C++.
If this is not the case then csharp should flag the 2nd line as an
error if it doesn't know what USER_DATA_OFFSET is. Better than leaving
it as 0 and letting it compile without problems. Now I need to verify
that all constants are used after they are declared.