My c was not very good to begin with, but my old brain is failing me more and more lately.
Are these two the same?
JamesCode:char* ss ; ss = GetInfo() if(ss && ss[3]) == '2' if (ss && ss[3]) == 50
My c was not very good to begin with, but my old brain is failing me more and more lately.
Are these two the same?
JamesCode:char* ss ; ss = GetInfo() if(ss && ss[3]) == '2' if (ss && ss[3]) == 50
They are, if you assume an ASCII character set.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thank you!
James
In addition to what @Salem said, "ss" should be pointing to a legitimate character array.
As written, ss is uninitialized.
I'm not sure what "GetInfo()" is.
Please provide a small but complete program that can be compiled and tested.
More code is irrelevant.
Salem gave the answer to the question asked.
James
Hmm... but your code is syntactically incorrect to begin with. I don't see why you couldn't have written a program like this:
Then upon compiling it, running it, and seeing that the output was:Code:#include <stdio.h> int main(void) { printf("%d=50?\n", '2'); return 0; }
ask if it was guaranteed that '2' == 50, upon which Salem's answer would apply.Code:50=50?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks guys I do appreciate the info but....
I am working on a new Basic -> c/c++ translator base on the original BCX.
There is no provision for parsing single quotes that are so prevalent in c code, as in the example.
I can use ASC("2") instead of '2' which mimics the c nomanclature and translates to 50.
So my Basic code is:
Code:If ss AND ss[3] = ASC("2") Then 'do your stuff End If
And it translates to:
Code:if(ss && ss[3]) == 50 { // do your stuff }
James
> If ss AND ss[3] = ASC("2") Then
You could translate it to
if(ss && ss[3]) == "2"[0]
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.