CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Gnu C++

  1. #1
    Join Date
    Oct 2002
    Location
    Ukraine
    Posts
    7

    Post Gnu C++

    Is GNU compiler is good enough to be used for commercial projects

  2. #2
    Join Date
    Jun 2002
    Location
    Newyork, USA
    Posts
    39

    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

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    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.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  4. #4
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    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.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    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.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    Jun 2002
    Location
    Newyork, USA
    Posts
    39

    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

  7. #7
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    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 *0;
    *
    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.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  8. #8
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    By the way....

    It can be usefull to develop the habit of writing if() statements in reverse order, like
    PHP Code:
    if(== 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(i){/*...*/
    will generate an error, since '5' is not a lvalue.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  9. #9
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    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.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  10. #10
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    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

  11. #11
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    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?
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    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.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    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
  •  





Click Here to Expand Forum to Full Width

Featured