Няшная / Говнокод #26006 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
// https://gcc.gnu.org/onlinedocs/cpp/Directives-Within-Macro-Arguments.html

// Occasionally it is convenient to use preprocessor directives within the arguments
// of a macro. The C and C++ standards declare that behavior in these cases is
// undefined. GNU CPP processes arbitrary directives within macro arguments in
// exactly the same way as it would have processed the directive were the
// function-like macro invocation not present. 

// If, within a macro invocation, that macro is redefined, then the new definition
// takes effect in time for argument pre-expansion, but the original definition is
// still used for argument replacement. Here is a pathological example:

#define f(x) x x
f (1
#undef f
#define f 2
f)

// which expands to

// 1 2 1 2

Ну и хуйня.

Запостил: j123123 j123123, (Updated )

Комментарии (6) RSS

  • а можно пример того, когда это надо за чем либо, кроме как для написания кода, rоторы кроме гнуси нигде не скопулируется?
    Ответить
  • #define f(x, y, z) g(x), g(y), g(z)
     
    #define g(x) x
    vector<int> bagor = {f(1
    #undef g
    #define g(x) x+10
    , 2
    #undef g
    #define g(x) x+100
    , 3)};
    #undef g


    https://ideone.com/MkhfBe
    Ответить
    • #define f(x, y, z) g(x), g(y), g(z)
      
      #define g(x) x
      vector<int> bagrinho = {f(1
      #undef g
      #define g(x) x+10
      , g(2)
      #undef g
      #define g(x) x+100
      , 3)};
      #undef g
      
      // 101 202 103


      https://ideone.com/BnawWy
      Ответить
  • Походу в сишке осталось ещё много сюрпризов...

    Кстати, а через это объявление макросов посреди их использования можно замутить что-то реально полезное?
    Ответить

Добавить комментарий

Семь раз отмерь — один отрежь, guest!

    А не использовать ли нам bbcode?


    8