Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Syntax Error with Q_ASSERT

Syntax Error with Q_ASSERT

Scheduled Pinned Locked Moved Solved C++ Gurus
25 Posts 5 Posters 9.3k Views
  • 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.
  • Chris KawaC Chris Kawa

    @Wieland I don't think it works. It just compiles ;)
    Well you could use something simpler:

    define MY_ASSERT(...) (!(__VA_ARGS__) ? qt_assert(#__VA_ARGS__,__FILE__,__LINE__) : qt_noop())
    

    and that should be ok, but it has the same drawback I described earlier - it changes the expression it tests by adding extra () around it. Admittedly it's not a big deal and it should work as expected most of the time.

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #21

    @Chris-Kawa Yes it works; funny that it doesn't work for you. Who knows why..

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #22

      @Wieland Maybe I messed up something. http://ideone.com/XKJUnV

      ? 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        @Wieland Maybe I messed up something. http://ideone.com/XKJUnV

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #23

        @Chris-Kawa Ha! Just found out that #define FIRST(A, ...) A doesn't work as expected (with MSVC): It doesn't give us the first argument only, instead it just gives all arguments (like __VA_ARGS__). Maybe I'm wrong here again, but that looks like a bug in MSVC to me and it also explains why the code works.

        Edit: Maybe it's really a bug in VC's preprocessor, at least someone on SO says so. And the workaround he presents actually seems to fix it, so now my code doesn't compile with MSVC anymore.

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #24

          Thanks everyone for watching me stumbling around like a clown :)

          mrjjM 1 Reply Last reply
          2
          • ? A Former User

            Thanks everyone for watching me stumbling around like a clown :)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #25

            @Wieland
            Well to be fair, fooling around with Variadic Macros takes more balls than entertaining
            clueless children - so it was educational to see that even in 2016, you cannot trust the preprocessor
            to work the same across compilers. :)

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved