Defining regions in code

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

According to MSDN Visual Studio is supposed to support regions in C code.

#pragma region test
...
#pragma endregion

Thing is it doesn't work. I define a region and it isn't noticed by Visual Studio in AS6. I can't collapse it.

Is there any way to define user regions in the source code? I know you can go through and manually outline code, but it's pointless because it isn't saved and you have to do it every time you open the file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well that #pragma will be for the Microsoft compiler so won't apply to gcc but I did notice that it allows code folding around a

#ifdef FOO
  // code
#endif

So I guess you coul,d just use am dummy one of those.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The editor adds regions around "functional blocks"...

As far as I know, there are no keywords that add user defined regions (like the #region and #pragma suggested).

Please, add a improvement request in the external bugtracker, so that we are able to track it

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson: Sure, problem is you need to have automatic outlining on and it will outline everything, occasionally getting it wrong. That means you can't simply collapse everything and end up with a reasonable display, and since VS doesn't remember collapsed sections once a file is closed it doesn't really help.

meolsen: I will do that, thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be honest I've never really see the attraction of code folding. Is it not just saying that either you need a larger monitor or to split the source more logically between files?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is an age old argument, but I find there is only so much splitting you can do in a sane way. For example I have a large select statement which has to handle 50+ different commands that my device can receive. Even if I made every command into its own function and grouped them in files it would still be massive and hard to work with. Additionally you end up with lots of external variables just so you can pass information between source files that would otherwise be local.

State machines are another classic space hog. Collapsing regions really helps to hide irrelevant code while not getting too silly with millions of source files. Getting a larger monitor doesn't really help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Code folding IMO can be handy at times; I don't use it that often.

Monitors have this peculiar aspect ratio that they are usually much wider than high nowadays; if you think about it's stupid really :D (at least for code/documents). But rotating a widescreen 90 degrees just looks silly and I can't get used to it :)

What can be handy is to have two monitors;or maybe even three.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have two monitors, a widescreen and 4:3. It still isn't enough :-)