Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Identifying sequence point errors in VS6

Identifying sequence point errors in VS6

Scheduled Pinned Locked Moved C / C++ / MFC
csharphtmlvisual-studiocom
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chintoo723
    wrote on last edited by
    #1

    See http://c-faq.com/expr/evalorder1.html[^] and http://c-faq.com/expr/seqpoints.html[^]. a[i] = i++ is disallowed. GCC has flags "gcc –Wsequence-point –Werror " to detect these errors, can microsoft compiler detect this? I use Visual Studio 6. If the CL compiler in VS6 cannot detect it, how about VS2003 and VS2005? thanks!

    J L 2 Replies Last reply
    0
    • C Chintoo723

      See http://c-faq.com/expr/evalorder1.html[^] and http://c-faq.com/expr/seqpoints.html[^]. a[i] = i++ is disallowed. GCC has flags "gcc –Wsequence-point –Werror " to detect these errors, can microsoft compiler detect this? I use Visual Studio 6. If the CL compiler in VS6 cannot detect it, how about VS2003 and VS2005? thanks!

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      I have not looked at the sights you provided, but that is not an error. A warning might not be a bad idea for that, but come on (it's legal code). INTP Every thing is relative...

      C R 2 Replies Last reply
      0
      • J John R Shaw

        I have not looked at the sights you provided, but that is not an error. A warning might not be a bad idea for that, but come on (it's legal code). INTP Every thing is relative...

        C Offline
        C Offline
        Chintoo723
        wrote on last edited by
        #3

        Is is actually disallowed in C as it can lead to undefined behaviour, see the two links I gave. GCC takes a command line option to detect this as a warning. thanks!

        J 1 Reply Last reply
        0
        • C Chintoo723

          See http://c-faq.com/expr/evalorder1.html[^] and http://c-faq.com/expr/seqpoints.html[^]. a[i] = i++ is disallowed. GCC has flags "gcc –Wsequence-point –Werror " to detect these errors, can microsoft compiler detect this? I use Visual Studio 6. If the CL compiler in VS6 cannot detect it, how about VS2003 and VS2005? thanks!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Did you change the warning level to 4? (Project->Settings->C/C++) Elaine :rose: The tigress is here :-D

          C 1 Reply Last reply
          0
          • L Lost User

            Did you change the warning level to 4? (Project->Settings->C/C++) Elaine :rose: The tigress is here :-D

            C Offline
            C Offline
            Chintoo723
            wrote on last edited by
            #5

            Trollslayer wrote:

            Did you change the warning level to 4? (Project->Settings->C/C++)

            I just checked with both VS6 and VS 2003, both of them dont detect and warn for a[i] = i++. Do you have VS 2005 to check this out? GCC 3.4.3 does, if you want to check this out with GCC. thanks!

            L 1 Reply Last reply
            0
            • C Chintoo723

              Trollslayer wrote:

              Did you change the warning level to 4? (Project->Settings->C/C++)

              I just checked with both VS6 and VS 2003, both of them dont detect and warn for a[i] = i++. Do you have VS 2005 to check this out? GCC 3.4.3 does, if you want to check this out with GCC. thanks!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I just tried on VS2005 with warning level 4 and it wasn't reported. The tigress is here :-D

              1 Reply Last reply
              0
              • J John R Shaw

                I have not looked at the sights you provided, but that is not an error. A warning might not be a bad idea for that, but come on (it's legal code). INTP Every thing is relative...

                R Offline
                R Offline
                Ryan Binns
                wrote on last edited by
                #7

                John R. Shaw wrote:

                I have not looked at the sights you provided, but that is not an error. A warning might not be a bad idea for that, but come on (it's legal code).

                Actually, it does violate the standard: "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored." The second sentence is the killer here. I think it's a silly statement, but perhaps that's just me. To me, it would be more intuitive to state that an object's value is not changed until the compiler reaches a sequence point - nice and clean and predictable, without preventing totally unambiguous code such as this example.

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                J 1 Reply Last reply
                0
                • C Chintoo723

                  Is is actually disallowed in C as it can lead to undefined behaviour, see the two links I gave. GCC takes a command line option to detect this as a warning. thanks!

                  J Offline
                  J Offline
                  John R Shaw
                  wrote on last edited by
                  #8

                  I assume you intended saying "It is actually disallowed...", but the rest of your statement does not support that nor does the standard. The term "undefined behaviour" does not disallow a programmer from doing it. It just says its behaviour is undefined in the standard and is therefore compiler dependent. Meaning that you can not determine the result when using a different compiler, provided it worked on your current compiler. A fully compliant compiler could compile that statement without giving any warning at all. But is should at the least give a warning and at the most consider it an error (becuase it is undefined behaviour). INTP Every thing is relative...

                  C 1 Reply Last reply
                  0
                  • R Ryan Binns

                    John R. Shaw wrote:

                    I have not looked at the sights you provided, but that is not an error. A warning might not be a bad idea for that, but come on (it's legal code).

                    Actually, it does violate the standard: "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored." The second sentence is the killer here. I think it's a silly statement, but perhaps that's just me. To me, it would be more intuitive to state that an object's value is not changed until the compiler reaches a sequence point - nice and clean and predictable, without preventing totally unambiguous code such as this example.

                    Ryan

                    "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                    J Offline
                    J Offline
                    John R Shaw
                    wrote on last edited by
                    #9

                    Ryan Binns wrote:

                    Actually, it does violate the standard

                    Actually, undefined behaviour is not a violation of the standard. It is what it says "undefined", that means it is up to the compiler [vender] to determine what its behaviour is. Personaly, I think it should translate into:

                    data[i] = i;
                    ++i;

                    OR

                    data[i] = (temp = i + 1);
                    i = temp;

                    but that is just my opinion. INTP Every thing is relative...

                    1 Reply Last reply
                    0
                    • J John R Shaw

                      I assume you intended saying "It is actually disallowed...", but the rest of your statement does not support that nor does the standard. The term "undefined behaviour" does not disallow a programmer from doing it. It just says its behaviour is undefined in the standard and is therefore compiler dependent. Meaning that you can not determine the result when using a different compiler, provided it worked on your current compiler. A fully compliant compiler could compile that statement without giving any warning at all. But is should at the least give a warning and at the most consider it an error (becuase it is undefined behaviour). INTP Every thing is relative...

                      C Offline
                      C Offline
                      Chintoo723
                      wrote on last edited by
                      #10

                      John R. Shaw wrote:

                      A fully compliant compiler could compile that statement without giving any warning at all. But is should at the least give a warning and at the most consider it an error (becuase it is undefined behaviour).

                      So it may be the case that the C compilers shipped with VS6, VS2003, VS2005 all aren't fully compliant with the standard. What is puzzling is, they dont qualify your "at the least" part, forget about "at the most" part. thanks! -- modified at 0:55 Sunday 19th March, 2006

                      J 1 Reply Last reply
                      0
                      • C Chintoo723

                        John R. Shaw wrote:

                        A fully compliant compiler could compile that statement without giving any warning at all. But is should at the least give a warning and at the most consider it an error (becuase it is undefined behaviour).

                        So it may be the case that the C compilers shipped with VS6, VS2003, VS2005 all aren't fully compliant with the standard. What is puzzling is, they dont qualify your "at the least" part, forget about "at the most" part. thanks! -- modified at 0:55 Sunday 19th March, 2006

                        J Offline
                        J Offline
                        John R Shaw
                        wrote on last edited by
                        #11

                        I would need to look it up, because I never understood why it would be classified as undefined behaviour. :doh: My answer was very weak and I should not have attempted it [without research], becuase it actually applies to the "old argument" below, following my explination of what I ment. I said "at the least" because if it is undefined behaviour then it would be compiler dependent (non-portable) and a warning should be generated to inform the programmer of this. I said "at the most" because if it is undefined behaviour then it would be compiler dependent and an error would force the programmer not to write non-poratable code. I believed it was consider undefined behaviour in the passed, which means the compiler vender could decide what behaviour to apply, and still be fully compliant. This may no longer be the case, as the behaviour may now be deifined. Here is the old argument: int i = 0; i = i++; Should i now be equal to 0 or 1? My answer and the answer Microsoft chose is 1, which I think is the only logical answer. But there where those who disagreed and said the answer should be 0, because they believed that was the intent of the progammer. So if you throw out logic and just consider the intent, then the language would not be able to define the behaviour. I think the real problem was that different venders had already implimented different solutions, before the standared was complete. When I originaly gave my answer of 1 to that question (years ago), I was informed that my answer was wrong, becuase it was undefined and therefore could be either 0 or 1. VS6 may be fully compliant for C (?), but it is not fully compliant with the C++ standard. VS2003, according to Microsoft, is a full ASCII/ISO C++ Standards compliant compiler. INTP Every thing is relative...

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups