Visual C++ does not highlight userTypes by default like; vector or MyCustomType; I've gotten used to this in C# and am wondering is there some way to get it to highlight userTypes for c++. I have checked in the fonts and color settings; User Types is set to a color but it has no affect in the editor.
No, there is no way to do this in Visual Studio 2010.
The reason is probably because C++ is notoriously hard to parse and determining what tokens are class names would require a lot of processing. This was probably deemed impractical because it would be too slow, though I can only guess.
This absolutely CAN be done!
I do it all of the time with my C++ types because I have my own typedefs for any type which is not strictly defined (pretty much all of them). Defining my own types prevents future incompatibilities (or at least mitigates them), as well as helps with portability. However, it requires an extra step before the types are highlighted properly.
Simply create a plain text usertypes.dat file in the same directory as devenv.exe using a standard text editor.
Put one type name on each line.
Then restart the IDE.
There is also a tool that manages this if you have complex needs that can be found at:
http://msmvps.com/blogs/p3net/archive/2010/06/27/updateusertype-visual-studio-addin.aspx
I used to use Visual Assist X for highlighting and intellisense while coding C++ projects that use a lot of templates.. This used to help me quite a bit.
http://www.wholetomato.com/downloads/
You could give it a try. But I must say it relatively reduces the speed of VS. Install the free trial and if you don't like it you can always remove it..!
Related
Often while writing or editing C++ code in VS I end up messing up by not having matching braces { or }. So I was wondering is there a tool that prevents writing { in a sense that when you press { key it automagically generates
{
}
and puts cursor between braces. Ofc one might want { in a string, so tool would have to allow that, also forcing closing of the string would be nice feature(I think Eclipse has it).
Visual Assist X does this, but it's not free.
On the other hand, you can try to write a macro for it yourself. It's easy enough to write a macro, although it's very difficult to get near-100% accuracy.
Visual Assist X does this and a lot more useful things for C++ developers, but unfortunately it's not free.
However, there is a free Brace Completer extension written by Joel Spadin that does precisely this. Download it here from the Visual Studio Gallery. It's an excellent product.
His description does mention that Microsoft's Productivity Power Tools extension now includes brace completion functionality, but that's a pretty heavy extension. Since I don't use or want most of those other features, I prefer to continue using Joel's one trick pony.
Also, it's never been clear to me from the description of PPT whether it works with C++ code. Most of the extensions focus on C# and VB.NET, which is nice as far as it goes, but doesn't help us C++ devs much. Joel's extension works great with C and C++.
Finally, never fear if you do accidentally mis-match a pair of braces. All versions of Visual Studio come with a handy tool that can catch mistakes like these. It's called the compiler. :-)
A very very simple plug-in would be
When typing { directly type } then head back to fill in the scope.
Same goes for ( and )
Never a mismatch.
ReSharper does this too, but again its not free.
Not sure if CodeRush Xpress does it, it probably does as it does similar stuff to ReSharper. There is a free version of that.
For more information on that look here:
CodeRush Xpress
This is basically a duplicate of:
Netbeans or Eclipse for C++?
But, that question as 3+ years old, and a lot has changed since then.
I have a large code base with a custom (but Makefile based) build system. The areas I am specifically wondering about include:
Syntax highlighting
Code navigation.
Code hints.
"ReSharper style" code helpers.
Documentation integration.
Debugger UI and features.
Has anyone had the chance to evaluate both Netbeans and Eclipse?
EDIT: As a followup question, are any of the Netbeans users here concerned with its future given Oracle's recent bad history with "open" efforts? (Open Solaris, MySQL, Open Office)
Thank you
I cannot comment on eclipse, but on netbeans 7 I will say things that are very important for me and that work fine so far:
code completion, go to declarations
pkg-config automatic include management for parsing
stuff that sometimes works and sometimes don't
find usages, sometimes it might fail to find usages in other open projects
debugger sometimes gets confused with unittest-cpp macros and it will not go on the appropiate line
stuff that are not yet working and i care deeply:
C++0x syntax highlighting (auto, lambdas, enum class, variadic templates, none of them are recognized by the built-in parser)
stuff that is not quite working but i could not care less:
git integration. I enjoy using git from command-line so this is a non-issue
in all, the IDE is very usable. I hope to have a chance to try out latest cdt on Indigo Eclipse, but so far i haven't that much of a real reason to investigate
I cannot comment on Netbeans, but I can offer you information on Eclipse. I work with C++ on UNIX systems, and I have started to use Eclipse when exploring large code bases that I know little about. I don't use it to build, but it would be easy to integrate our build system with it as one only needs commands.
Eclipse has most of what you are looking for: (I'm speaking of Eclipse/CDT)
Not only can you completely customize your syntax highlighting, you can also have it format the code with templates. My company has a code standard for spacing, tabs and formatting of functions and conditional code, and with little effort I was able to modify an existing template to meet our code standards.
The navigation is not bad, if you highlight and hover over a variable, it shows you the definition in a small pop-up bubble. If you do the same for a type, it will you show you where the type is defined. For functions, it will show the first few lines of the implementation of the function, with an option to expand it and see the whole function. I find all of these nice for code discovery and navigation. You can also highlight a variable, and use a right-click menu option to jump to its declaration.
I suppose by code hints you are referring to something like intellisense? This is the main reason why I use Eclipse when looking over a large code base. Just hit the '.' or '->' and a second later you get your options.
The debugger UI is quite capable. You can launch gdb within the tool and it allows you to graphically move through your code just as you would in a tool like ddd or Visual C++. It offers standard features like viewing registers, memory, watching variables, etc.
That being said, I have found some weaknesses. The first is that it doesn't really strongly support revision control systems outside of CVS and SVN very easily (integrated into the GUI). I found a plug-in for the system we use at my company, but it spews XML and Unicode garbage. It was easier to just use the revision control on the command line. I suspect this is the plug-in's issue and not Eclipse. I wish there were better tool integration though.
The second complaint is that for each project I have to manually setup the include directories and library paths. Perhaps with an environment variable this could be circumvented? Or I may just do not know how to set things up correctly. Then again if it is not obvious to a developer how to do this, I consider that a weakness of the tool.
All in all I like working with Eclipse. It is not my main editing environment, but I appreciate it for working on large code bases.
I'm a huge fan of Netbeans. I am in a similar situation to yours, but creating the project was very easy. Just point Netbeans at where the code is checked out and it figures out most things for itself. I rarely have to do any configuration. One thing to note though, if your tree is very large, it can take some time to fully index - and while it does, memory and cpu will be hosed on the box.
The integration with cvs is awesome, and the Hudson integration is very cool for CB. I've not used Git myself, though I should imagine it's a no-brainer.
One thing that does irritate me no end is that it does not behave very well with code relying heavily on templates. i.e. shows lots of warnings and errors about types not being found etc.
I have not used the latest version of Eclipse, I tried the major release before the current one and gave up because it did not have the same smooth project integration with the makefiles etc. I find it's not as nice if you don't want to use it's make system - though I could be wrong.
I don't use any of the code formatting provided, I instead prefer something like AStyle instead. I know that NetBeans does a good job with Java - but have not used it for C++. CDT I seem to remember doing some odd stuff with indentation when formatting C++ code - esp. if templates are involved - but that was atleast two years ago.
Hope some of it helps - the best way to do this is to download and try for yourself and see what works for you. Anything we tell you is purely subjective.
I used to work with Netbeans with MinGW, I Just tried 7.0.1.
I currently use Eclipse Indigo with CDT and MinGW - It's better performance wise (less CPU & Memory).
Netbeans creates a makefile to compile all the time,
In Eclipse you can build directly with the CDT-Toolchain or use Makefile - Eclipse is more flexible.
Debugging: Netbeans might be better in Solaris/Linux.
I Personally rather eclipse over Netbeans, I think eclipse is more professional.
One particular issue that causes me quite a lot of grief with Netbeans 7.0 is that it tends to want to work with utf8 files, and not all of out c++ projects are utf8. It will issue a warning about opening such a file, and if you do open it, will corrupt said file, which is a pain.
I've not found out how to properly make netbeans handle this. Apparently the encoding can be changed, but for the entire project. So presumably changing it to us-acii would stop this problem, although non ascii characters wouldn't display properly.
I just want to see my own datatypes/functions/function parameters with a different color.
I have used Visual Assist X before, but it stopped working for some unknown reason. It doesn't color the custom functions or function parameters every time. Also, my trial time is over soon, and I am not going to buy something that doesn't work properly or whose most features I don't even use.
So, if there's any free syntax highlighting that colors all functions, etc. for Visual Studio 2008, that's what I'm looking for.
You can create a file(usertype.dat) containing any names, these will be colored differently.
You can read more about that here
Unfortunately you can't give your different types different colors from there but at least you can get your own types colored.
To color your own data structures, functions and parameters, a highlighter should know that they are your own data structures, functions and parameters. It means it should be able to parse C++ code. But, C++ code parsing is extremely hard task, so no one will do that just to highlight a couple of words. So, this may be just an associated feature of some powerful tool that definitely costs money.
Actually, it seems there are just some problems with your environment. I use Visual Assist X with Visual Studio 2003, 2005 and 2008 and it works like a charm!
I'd recommend proceeding with Visual Assist X if you are serious about MS VC++ programming. Actually, it is a must have tool as, say, ReSharper for CSharpers.
If you have the option to use Visual Studio 2010, there is Highlighterr, which changes the colors of classes, structs, macros and typedefs. There doesn’t appear to be a version for Visual Studio 2008, but what are you waiting for? ;-) C++0X awaits…
Please guide me, as how to convert a C++ code of Borland 2007 in to Visual Studion 2010 code. I just need to ask, whether to write all th code again for 2010 or is there any shortcut for this conversion/migration.
i did and it worksd for me-
remove .h from include
do not do it for other libraries,
remove clrscr(); everywhere and replace by system("cls");
finally after writing all #include stuff add this-
using namespace std;
it allows you to do things like cin>> cout<< etc.
If the code was written portably to begin with, there should be no issues. Other than that, all I can say is to run the code through Visual Studio's compiler and see if you get errors or anything of that nature.
After that, test the output to ensure you're getting correct behavior.
Are you using any Borland proprietary components?
If so, I'd say you're out of luck. You'd have to replace those components, and this is likely not to be easy. I should say you may not find a tool that can automatically "translate" these.
If not, it should be easier. But be aware that Borland compiler has support for many things that are not C++ standard. If your code is portable enough, you'll be fine just recompiling it under VS. You might have to change some header files, replace some pragmas, but nothing too complicated.
If you're using the Borland GUI (TButton, etc) then you have some real work to do. Every one of them will need to be replaced with something Visual Studio knows - most probably MFC. About the time Visual C++ 4 was released I actually wrote a giant set of scripts (mostly using sed and awk) to convert a large codebase - it was not pleasant, the parameters are in different orders and the methods return slightly different types. It was worth it in that case - tens of thousands of lines of code and a strong business desire to switch tools. In your case since you say you have a "simple windows form with new controls" I would say start a new project, build the form, then copy your old code in - entire files for classes and business logic, clumps of lines for event handles in the gui. Test very carefully.
Also, the default MFC look and feel isn't the same as the Borland default look and feel. On that long ago project we had to look identical so we had to play with a lot of properties and options. Be sure to ask your bosss if this matters.
I've been using VS2005 and VS2008 now for a while, with C#. Without any additional tools I could hit ctrl k + d and the code would nicely reformat. Why doesn't C++ do this?
It's the same Visual Studio after all. Is there a way to enable it?
A second part of this question is related, for those who've been using resharper with C#, is there a similar tool for C++?
You can use Ctrl-K+Ctrl-F for "format selection".
Link
It's probably there, but mapped to a different keyboard shortcut. For example, on my VS2008 install Ctrl+K,D doesn't map to anything but Ctrl+E,D maps to the Edit|Advanced|Format Document command.
You can always use AStyle to format your code. Works great!
For me it's always been select text, CTRL + K, F. It doesn't do as well as in Visual C# though; there are no customization options beside the most basic ones.
Edit: in 2017 this answer seems outdated. I recommend clang-format for "anything", for "anyone".
Original answer:
Ontopic: In VS2008 Express Format Selection is ALT+F8 and CTRL+K, CTRL+D is mapped to Format Document. It's probably the same in professional versions of VS2008.
Less ontopic: I tend to avoid source code formatters for C++ as I feel they generally often does more harm than good. Why? Codeformaters has to "read" the code and understand what the different code statements do. This is quite easy in e.g. Java where the syntax is straight forward. C++ is a very complex language. There's 10 ways to do just about anything. You can use macros, defines, typedefs and whatnot. Classes are usually defined/declared in two different files. This is also the reason that Intellisense seems to fail quite often - VS2008 fails parsing the code correctly. It's very hard for an IDE to know what all statements is and how to format them. Although it may work ok most of the time, you can be pretty sure that it will give bad results now and then. I'm guessing Microsoft didn't spend too much time customizing the code formatter for C++ as they realize that most C++-programmers do this by hand anyways. I rarely miss it, except when some co-worker of mine isn't following the company standard.
**For C/C++ code formatting you can use bcpp [ apt-get install bcpp ].
This program will run under Linux/Unix and MS DOS V3.3
There is config file so you can be creative.
**Interesting tool for C/C++/C#/Java proposed by Qt is astyle
[ apt-get install astyle ]