Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя harhrayr

Автор harhrayr, 11 лет назад, По-английски

Does anybody know how to expand macros in visual c++ ?

For example.

#define FOR(i, n) for(i = 0; i < n; ++i)

It's faster to write FOR(i, n) than for(i = 0; i < n; ++i), but for(i = 0; i < n; ++i) is more

beautiful and comfortable, so I want to expand FOR(i, n) pressing a button or buttons. Is there

any extension for visual c++ 2010 or 2012 ?

Thanks.

  • Проголосовать: нравится
  • +19
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It's called code snippets, but I don't know how to use them in Visual C++. Try to google it.

  • »
    »
    11 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

    I know about snippets, there is for snippet in visual c++ 2012, but when you select it, you must write i and n. It takes a little bit more time.

    http://www.youtube.com/watch?v=j5cSxC6pKnI 2:41 , this is what I want.

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I don't know about vs, bit usually you can configure macroses and print some text including variables, that you can change. so you should add macro with only pain text

      • »
        »
        »
        »
        11 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Yes it's possible, it can be done by creating a snippet, which prints plain text and then change the variables.

»
11 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

in Microsoft Visual studio Express 2012 write "for" and double tap the "TAB" button to automatically insert the for loop body for (int i = 0; i < length; i++) {

}

it is like the above after that you can change the "length" with anything you want

»
11 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

If you get used to the long version, it will be faster to write than short.

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    I think that the time spent typing in the solution is negligible altogether in comparison to the time spent reading, thinking, testing and debugging. Also, most people here are fast typists anyway. Thus, in my opinion, shorthand macros like FOR succeed only in making the code less readable, which leads to harder debugging.