Category: visual studio

How to count lines of code in Visual Studio

How to count lines of code in Visual Studio

Calucating Code metrics in Visual StudioUntil this morning, I didn’t realise that Visual Studio (even the free Community Edition) has this built in. I was curious to see how much code I’d written so far for my game processing engine.  Development comes in leaps and bounds during evenings and weekends.

Visual Studio has Code Metrics in it. You can do this for any project that builds correctly. To show this you have to do View => Other Windows => Code Metrics Results. That displays the window. Then you have to go on the Analyze Window, and click Calculate Code Metrics.

Lines of code

However you might want to take these with a pinch of salt. As I understand it, Lines of Source Code is calculated from the il code output from the compiler. The last column (Lines of executable code) suggests that most of my program is comments which is wrong! There is however a fair amount of data in the form of Constructor initializations, and one file of 1290 lines has over 1,000 such initializations.  You can read what the other columns mean and everything you ever wanted to know about code metrics on the Microsoft site.

Out of curiosity, I manually counted the number of lines in this project. There are 15 files and they added up to 3700 lines but that includes comments and blank lines.  A quick search for // found 119 which probably means I should improve my commenting. Blank lines is probably something similar. So we’re talking 3700-1000 (constructor initializers)-119 (comments) -119 (blank lines) = 2462 lines of code so far. That’s working tested code mind you.


C11 and C17 support in MSVC

C11 and C17 support in MSVC


The letter C
Image by Peggy und Marco Lachmann-Anke from Pixabay

Microsoft have announced that they will be supporting both C11 and C17 in Visual Studio 2019 version 16.8 Preview 3. All the required features but not optional features and not VLAs (Variable Length Arrays) which is considered unsafe.

One of the complaints has been that Microsoft always prioritised C++ over C for many years. C was supported inasmuch as it was needed for C++. Until fairly recently C++ was a superset of C and you could compile C program as C++. Just change the extension to .cpp.

That said, I will probably continue to write C code as C99 for now and take a look at the C11/C17 features such as restrict, stdnoreturn and so on.  Note C17 is considered a bit of a bug fix for C11.