harhrayr's blog

By harhrayr, 13 years ago, In English

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.

  • Vote: I like it
  • +19
  • Vote: I do not like it

»
13 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
13 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

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

»
13 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    13 years ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    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.