|
Hi all, i dont get it, heres some "sample" code to explain my problem:
const int SOME_INT = 100; // notice the "const" at the start
int num=0;
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
// whatever
};
gives me: error C2051: case expression not constant.
BUT:
#define SOME_INT 100; // using define instead
int num=0;
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
// whatever
};
Gives me no trouble! WTF???? "case expression not constant"???? isnt SOME_INT clearly defined as constant in the first case??
|
|
|
|
|
shouldn't this be:
switch(num)
{
case SOME_INT:
ATLTRACE("someint");
break;
default:
};
Cheers,
Andy
|
|
|
|
|
Sorry, the ":" after case is a mistake i made while writting the post ( edited the post and corrected it now), but even without it, if you try to compile the code you wrote, and assuming you declared SOME_INT as
const int SOME_INT = 0;
it will give you the error, but if you declare it like:
#define SOME_INT 0
then it will work fine.
any idea why?
|
|
|
|
|
AndyQ wrote:
still classed as a variable (albeit a const).
Contradictory statement.
A variable cannot be constant and neither can a contant be variable.
Bikram Singh
|
|
|
|
|
Are you using VC6? Because it compiles just fine in VC.NET2003 (once the default case is filled in).
According to the standards, it should work, so either your compiler is breaking the standards, or what you've posted isn't quite the same as what you've been trying to compile.
|
|
|
|
|
Curi0us_George wrote:
According to the standards, it should work
Yes it should, but with Microsoft, there's no more standard... they implement their compiler how they like...
TOXCCT >>> GEII power
|
|
|
|
|
Actually, I'm pretty sure that VC.NET2003 is as compliant with the standards as GCC.
|
|
|
|
|
As much as I hate quoting Joan Rivers, oh grow up.
Software Zen: delete this;
|
|
|
|
|
Heres the REAL deal
in a file (appconsts.cpp)
#include "appconsts.h"<br />
const int COLID_PLV_NAME = 0<br />
const int COLID_PLV_PHONE = 1<br />
const int COLID_PLV_REP = 2
and in another file (appconsts.h) wich is included everywhere...
extern const int COLID_PLV_NAME;<br />
extern const int COLID_PLV_PHONE;<br />
extern const int COLID_PLV_REP;
and finally, in the LVN_COLUMNCLICK handler of one of my views (appconsts.h included here of course)...
switch(ColIdx)<br />
{<br />
case COLID_PLV_NAME:<br />
break;<br />
case COLID_PLV_PHONE:<br />
break;<br />
case COLID_PLV_REP:<br />
break;<br />
default:<br />
return 0;
} Looks right no?, but it gives me...
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(204) : error C2051: case expression not constant
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(207) : error C2051: case expression not constant
C:\DEV\PROJECTS\BOLETAJE\1.0_CURRENT\ProvidersView.cpp(210) : error C2051: case expression not constant
i just dont get it!
|
|
|
|
|
The case expression must be constant at compile time. The circumstances you've described do not let the compiler know the value of the case expressions until link time.
Software Zen: delete this;
|
|
|
|
|
how do i get the text from a combobox ?
i.e. not in drop down list / what the user types in
(and it is not m_combo.GetLBText(-1, strTemp); )
|
|
|
|
|
nevermind all,
got it done thru:
<br />
GetDlgItemText(IDC_MYCOMBO, strTemp);<br />
|
|
|
|
|
go to Class Wizard and associate the control with category of Value and of Type CString,
then through the DDX, you can:
UpdateData();
m_strCombo1;
|
|
|
|
|
I'm trying to new a struct, which works fine, but if I view the members of that struct in the watch window the values appear as
I've also tryed a malloc on the struct, but that has the same effect.
Any one got any ideas?
Cheers.
James.
|
|
|
|
|
Hello!! I need some help from you.
Is there any unic number that identify a PC (server or workstation?
In this case, how can I get it from my VC++ app? and is posible execute this function in a PC #1 and get it from a PC #2.
Many thanks in advance
Xavier
|
|
|
|
|
The obvious choice would be the IP address.
If you know the name of the machine then just call:
gethostbyname
Here's the link to MSDN
Hope this helps,
Andy
|
|
|
|
|
As to sending and receiving ip address or hostname - you need to use sockets.
(just see MSDN. You can find it by socket, recv, send, connect, listen etc. functions)
However, that requires a server part of your program running remotely.
|
|
|
|
|
Sorry for reposting this, but I thought I may get some help now that it's the weekend...
I have now undertaken rewriting the serial portion of my code to use CreateFile and the like. It's all a bit complicated though, and being new to this, I have a few questions. It starts with overlapping, and also involves WaitCommEvent and GetCommMask. I did a search on the topics and read a few articles that were found, but while they cleared a few things up, they still left me with a few questions unanswered.
First, I understand that SetCommMask allows you to screen for only a few of the events. But after calling SetCommMask to look for only what you want, how does one screen for these events and process them appropriately? I know you can use WaitCommEvent, but in that case, why would you even need GetCommMask? I also need to use overlapping for this program, but I'm not sure how to implement it or even what it actually is (do I need to use the overlapped structure at all?).
I was able to find this piece of example code on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring_communications_events.asp
I do not fully understand how it operates, though.
Also, this article was very helpful, to a point: http://www.codeproject.com/system/serial_com.asp
Where I got lost was the huge block of code where he uses the OVERLAPPED structure and the Threadfn function, after which he writes "If you understood the above code , you will understand the whole of this article and the source code provided." Gulp. Basically, I have trouble understanding what he does there and where that overlapped structure comes into play.
As always, the help is very much appreciated.
|
|
|
|
|
Why do you think you need to use overlapped IO?
IMO it only makes sense to consider overlapped IO with serial ports if you plan to operate multiple ports on a single thread.
What sort of protocol are you implementing?
Paul
|
|
|
|
|
Hi,
I just couldn't find any other forumn, where I can post my C++ questions. So sorry for posting it here in the VC++ discussion board.
Pl. see the code below.
void Allocate( char* s )
{
s = (char*)malloc( 100 );
}
int main( )
{
char* s = NULL;
Allocate( s );
strcpy( s,"Test"); //I know that this will fail. b'coz I still have a NULL pointer in s. Initially s was pointing to NULL, and from the function Allocate 100 bytes of memory was allocated in some memory location, and address of s was made to point to that location. But inside the main, s is still pointing to NULL. Pl. correct me if I am wrong.
}
Now my question is
void Allocate( Base* s )
{
s = new Base;
}
int main( )
{
Base* obj = NULL;
Allocate( obj );
obj->some_member = 20; // this works...
}
So I assume, object pointers are passed to functions in a different way compared to primitive type pointers. Can anyone pl. comment on this.
Regards
Jugs...
|
|
|
|
|
Anonymous wrote:
So I assume, object pointers are passed to functions in a different way compared to primitive type pointers. Can anyone pl. comment on this.
No, they aren't, and the second example shouldn't work any better than the first one does. There's no 'magic' when dealing with pointers.
In your case, you probably want the argument to Allocate to be a reference; i.e.
void Allocate( Base*& s)
{
s = new Base;
}
or
void Allocate( char*& s )
{
s = (char*)malloc( 100 );
// Probably better to use:
// s = new char[100];
// but remember when freeing to use 'delete []'
}
which will then do what you want. Alternatively, you could explicitly use a pointer to a pointer, but some people don't like that.
Steve S
Developer for hire
|
|
|
|
|
First function does not work because you have to pass an pointer to variable as an argument, and because variable is (char*) then pointer to it is (char**)
void Allocate( char** s )
{
*s = (char*)malloc( 100 );
}
Allocate( &s );
you should see that in your case when Allocate() function is entered then there is NULL in 's', as you defined it outside, not the pointer to address where 's' resides.
|
|
|
|
|
Dear,
I want to ask if there is any way to convert an integer value from "int" to "CY" ?
I need your help.
Hing
|
|
|
|
|
What is "CY"?
Color yellow?
Coordinate Y?
Maxwell Chen
|
|
|
|
|
CY is Currency, see this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm/chap6_03sp.asp
|
|
|
|