|
-
October 11th, 2002, 12:56 AM
#1
Gnu C++
Is GNU compiler is good enough to be used for commercial projects
-
October 11th, 2002, 08:55 AM
#2
Gnu C/C++ has certain disadvantages
GNU is free so people use it. In that programmers need to be extra careful. But once the application is developed it is ok.
eg. In GNU if you put if(a=5){} it won't throw any error , But I guess in Sun Workshop it does.
If you have Sun Workshop C/C++ 6.0 it is always better to use it.
Sujit
-
October 11th, 2002, 09:52 AM
#3
I have looked at the comp.lang.C++ newsgroup for a few months and the comments I have seen indicates that the current versions were more compatible with the C++ language standard than VC version 6 is. Microsoft has supposedly finally gotten the VC compiler to be quite compatible with the language standard but they have been slow to do so.
-
October 11th, 2002, 09:59 AM
#4
Re: Gnu C/C++ has certain disadvantages
Originally posted by sujit
eg. In GNU if you put if(a=5){} it won't throw any error , But I guess in Sun Workshop it does.
IMHO that is perfectly legal C++ code, thus no reason for a compiler to throw an error. A good compiler should throw two warnings, one about the conditional expression in the if() having side effects and another about the empty execution block of the if statement.
-
October 11th, 2002, 10:01 AM
#5
Re: Gnu C/C++ has certain disadvantages
Originally posted by sujit
eg. In GNU if you put if(a=5){} it won't throw any error , But I guess in Sun Workshop it does.
I would not want an error. A warning would help. Many programmers would not want even an error so the ideal would be to make the warning optional. Perhaps the GNU compiler creates a warning that is optional and perhaps the default is to not give the warning.
-
October 11th, 2002, 10:23 AM
#6
Use of if(a=5) {....}
Can Anyone please tell me the use of the statement
if(a=5) {....} in programming ,
The statement implies the statement inside the "if" block always will be executed , then why the if statement not simply the statement inside it.
Is it not contradict the features of if , is it not helpful in respect of programming to get an error in that statement ,
as I have not found any use of that statement. Rather sometimes programmers have to suffer a lot becouse of that minor mistake.
I am not contraditing your views , Just putting my views. Let me know your views.
Sujit
-
October 11th, 2002, 10:34 AM
#7
Re: Use of if(a=5) {....}
Originally posted by sujit
Can Anyone please tell me the use of the statement
if(a=5) {....} in programming ,
The statement implies the statement inside the "if" block always will be executed , then why the if statement not simply the statement inside it.
Is it not contradict the features of if , is it not helpful in respect of programming to get an error in that statement ,
as I have not found any use of that statement. Rather sometimes programmers have to suffer a lot becouse of that minor mistake.
I am not contraditing your views , Just putting my views. Let me know your views.
There is a difference between legal code and "moral" or useful code. This particular example indeed would be an error, but not a syntax error so you cannot expect from the compiler more than a warning. Have a look at this:
PHP Code:
int *i = 0;
*i = 1;
Is this legal, syntactically speaking? Yes. Is it an error, semantically speaking? Yes. What would you expect the compiler to do?
The compiler translates source code to machine code according to a set of rules. You break the rules, you get an error. By no means is the compiler supposed to analyse the meaning of the code you write. Modern compilers are able to detect problematic constructs and to warn the user, but they cannot and will never be able to think for the user.
-
October 11th, 2002, 10:38 AM
#8
By the way....
It can be usefull to develop the habit of writing if() statements in reverse order, like
PHP Code:
if(5 == i){/*...*/}
This ensures that at least for a subset of exrpessions the problem of typing "=" instead of "==" gets caught by the compiler.
PHP Code:
if(5 = i){/*...*/}
will generate an error, since '5' is not a lvalue.
-
October 11th, 2002, 10:48 AM
#9
Re: Use of if(a=5) {....}
Originally posted by sujit
Can Anyone please tell me the use of the statement
if(a=5) {....} in programming
It is obviously not practical to use the result of "a=5" as a condition as shown in that example but it is quite common to do something such as:
Code:
bool bResult;
if (bResult=Function())
I think that is something that is very controversial; many programmers would say that is very valid and many programmers would say it is inconsiderate and dangerous.
-
October 11th, 2002, 10:54 AM
#10
Re: Re: Use of if(a=5) {....}
I would clarfiy this by writing
Code:
bool bResult;
if ((bResult=Function()) == true)
which is clearer to the reader
-
October 11th, 2002, 10:57 AM
#11
Re: Re: Re: Use of if(a=5) {....}
Originally posted by Yves M
I would clarfiy this by writing
Code:
bool bResult;
if ((bResult=Function()) == true)
which is clearer to the reader
Isn't that a little bit too redundant?
-
October 11th, 2002, 11:13 AM
#12
Re: Re: Re: Use of if(a=5) {....}
Originally posted by Yves M
I would clarfiy this by writing
Code:
bool bResult;
if ((bResult=Function()) == true)
which is clearer to the reader
It depends upon who the reader is. I would not do that for my own programs. I would if the "reader" is (or might be) a beginner, especially a beginner that is a former COBOL programmer.
-
October 11th, 2002, 11:30 AM
#13
It is indeed redundant but is clearer since it does contain a comparison. Granted for a bool value it might be clear enough to leave it out. But for an integer value for example it is definitely clearer.
Code:
long nElements;
if ((nElements = Function()) != 0)
...
or
HRESULT hRes;
if ((hRes = COMFunction()) != S_OK)
Plus there is no overhead generated by the compiler, so it's only a textual clue to the programmer (and the reader) on what's going on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|