473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MS compiler bug?

Hi,

The following code-fragment won't compile in the .Net-studio but it does
compile in Borland. So is anyone familiar with this problem, or someone
knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

Anyone?
Jul 22 '05 #1
7 1290

"Martijn" <r.m.maatman_@_student.utwente.nl> wrote in message
news:c6**********@netlx020.civ.utwente.nl...
Hi,

The following code-fragment won't compile in the .Net-studio but it does
compile in Borland. So is anyone familiar with this problem, or someone
knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

Anyone?


No .NET is right. In this case constant expression means compile time
constant, which obviously dim isn't even though you've declared it as const.

The best way to do this is to use a vector.

#include <vector>

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
std::vector<float> derivative_state(dim);
...

Now I can't see the rest of your code, but I wouldn't be surprised if it
compiled unchanged, even though you've switched from an array to a vector.

john
Jul 22 '05 #2
"Martijn" <r.m.maatman_@_student.utwente.nl> wrote in message
news:c6**********@netlx020.civ.utwente.nl...
Hi,

The following code-fragment won't compile in the .Net-studio but it does
compile in Borland. So is anyone familiar with this problem, or someone
knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

It is not a constant expression, since it is not assigned a value at the
place of definition. It is as if you define a variabled-sized built in
array.

If you define dim inside the function scope then you will have no problem.
E.g.:

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
const unsigned SIZE=7;

float derivative_state[SIZE];
...
}


Ioannis Vranos

Jul 22 '05 #3

"Martijn" <r.m.maatman_@_student.utwente.nl> wrote in message
news:c6**********@netlx020.civ.utwente.nl...
Hi,

The following code-fragment won't compile in the .Net-studio but it does
compile in Borland. So is anyone familiar with this problem, or someone
knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

Anyone?


The reported error is correct because dim is not a constant as the compiler
cannot see its actual value (which should be a defined constant). However,
itīs hard to believe that Borland will compile this without at least a
warning. Try to increase your warning levels and recompile under Borland
(BTW which version?).

HTH
Chris

Jul 22 '05 #4
"Chris Theis" <Ch*************@nospam.cern.ch> wrote in
news:c6**********@sunnews.cern.ch:

"Martijn" <r.m.maatman_@_student.utwente.nl> wrote in message
news:c6**********@netlx020.civ.utwente.nl...
Hi,

The following code-fragment won't compile in the .Net-studio but it
does compile in Borland. So is anyone familiar with this problem, or
someone knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float*
current_state, float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

Anyone?


The reported error is correct because dim is not a constant as the
compiler cannot see its actual value (which should be a defined
constant). However, itīs hard to believe that Borland will compile
this without at least a warning. Try to increase your warning levels
and recompile under Borland (BTW which version?).


It is possible that Borland might have implemented variable length arrays
as a compiler extension? But from a C++ standpoint, dim isn't a compile-
time constant and cannot be used as an array size specifier (from a
Standard point of view....)
Jul 22 '05 #5

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177. 135...
[SNIP]> > The reported error is correct because dim is not a constant as the
compiler cannot see its actual value (which should be a defined
constant). However, itīs hard to believe that Borland will compile
this without at least a warning. Try to increase your warning levels
and recompile under Borland (BTW which version?).


It is possible that Borland might have implemented variable length arrays
as a compiler extension?

[SNIP]
Iīve also had that idea but I doubt that they do not at least give a hint
via a warning. Unfortunately I do not have a Borland compiler available to
check this. Hence, probably somebody else could shed some more light onto
this matter.

Chris
Jul 22 '05 #6
"Chris Theis" <Ch*************@nospam.cern.ch> wrote in message
news:c6**********@sunnews.cern.ch...

"Martijn" <r.m.maatman_@_student.utwente.nl> wrote in message
news:c6**********@netlx020.civ.utwente.nl...
Hi,

The following code-fragment won't compile in the .Net-studio but it does
compile in Borland. So is anyone familiar with this problem, or someone
knows how to solve it?

void MidpointSolver::Solve(float* next_state, const float* current_state, float time, float h, const unsigned int dim)
{
float derivative_state[dim];
...
}

The reported error is: C2057 - 'expected constant expression'. So the
compiler doesnt see 'dim' as an constant or something like that?!?

Anyone?

The reported error is correct because dim is not a constant as the

compiler cannot see its actual value (which should be a defined constant). However,
itīs hard to believe that Borland will compile this without at least a
warning. Try to increase your warning levels and recompile under Borland
(BTW which version?).

Many compilers support VLAs as a system extension, the same happens with
long long. All of course give an error when in strict ISO mode.


Ioannis Vranos

Jul 22 '05 #7
In message <c6**********@sunnews.cern.ch>, Chris Theis
<Ch*************@nospam.cern.ch> writes

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177 .135...
[SNIP]> > The reported error is correct because dim is not a constant as the
> compiler cannot see its actual value (which should be a defined
> constant). However, itīs hard to believe that Borland will compile
> this without at least a warning. Try to increase your warning levels
> and recompile under Borland (BTW which version?).


It is possible that Borland might have implemented variable length arrays
as a compiler extension?

[SNIP]
Iīve also had that idea but I doubt that they do not at least give a hint
via a warning. Unfortunately I do not have a Borland compiler available to
check this. Hence, probably somebody else could shed some more light onto
this matter.

Not BCB5, at least:

void Solve(float* next_state, const float* current_state,
float time, float h, const unsigned int dim)
{
float derivative_state[dim];

}

[C++ Error] Unit1.cpp(6): E2313 Constant expression required

--
Richard Herring
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.