Groovy hepcat Brian Wood jived with All on 21 Jan 98 06:44:54!
'/a'=?'s a cool scene. Dig it!
BW> Can someone help me understand why different compilers treat this
BW> code differently? Specifically Borland(3.0-4.52) -vs- Microsoft(8.00)
BW> cout << "The value of /a is " << (char)'/a' << endl;
BW> Borland will send a backslash. Microsoft, the letter a.
A backslash? Are you sure? Are you absolutely sure? You haven't got
your backslashes confused with something else, like, say, a forward
slash? Are you absolutely certain?
BW> or without the cast:
BW> cout << "The value of /a is " << '/a' << endl;
BW> Borland evaluates 24879. Microsoft 12129...??
BW> The problem has come up while dealing with command-line args in some
BW> older code I want to reuse, and it's driving me a little nuts.
BW> example command line:
BW> C:\THISPROG.EXE /a
BW> while (--argc && **argv++) {
BW> // case '/a': isn't evaluated consistently
BW> // Best way around this?
BW> cout << "\narg entered was " << endl;
BW> switch (*(int*) *argv) {
BW> case '/a':
BW> cout << "/a" << endl;
BW> break;
BW> default:
BW> cout << *argv << " (unknown)" << endl;
BW> break;
BW> }
BW> }
YIKES! None of that makes any sense at all, I'm afraid. You seem to
be getting a command line argument (ie., a string) confused with a
single char. And on top of that, you've confused a backslash with a
forward slash. And as if that isn't enough, you're trying to compare
a pointer to the command line argument with a pointer to whoknowswhat!
It looks to me what you're trying to do is read a command line
argument, compare it to the string "/a", and act acording to the
result of that comparison; right? Well, here's how (and bear in mind
that I come from C, and know little of C++):
if(argc > 1) /* make sure there are command line args */
while(--argc)
{
cout << "arg entered was ";
if(strcmp(argv[argc], "/a") == 0)
cout << argv[argc] << endl;
else
cout << argv[argc] << " (unknown)" << endl;
}
else
cout << "No args entered." << endl;
Wolvaen
... URA Redneck if you can take your bra off while driving.
--- Blue Wave/RA v2.20
---------------
* Origin: The Gate, Melbourne Australia, +61-3-9809-5097 33.6k (3:633/159)
|