Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What "are" the C++ GSL guidelines?

Stroustrup gave a talk last year about his GSL (Guideline Support Library). There is an implementation by Micosoft at https://github.com/Microsoft/GSL . I was under the impression that the GSL was supposed to advise on bad coding style, and suggest improvements.

To this end, I installed MSFT's GSL and created a C++ file:

#include <stdio.h>
#include <gsl.h>

int main()
{
        int *i = new int;
        puts("hello world");
} 

and built it using the Makefile:

msft : msft.cc
        g++ -std=gnu++14 -I ../../src/GSL/include $^ -o $@

.PHONY : clean
clean :
        rm -f msft

Obviously, there is a resource leak in the code caused by the new.

So now I'm confused.

  • What is the GSL supposed to actually do?
  • Where can I get the source code checker that warns of guideline non-compliance? Stroustrup seemed to imply that it actually exists as a tool, but is that the case?
like image 422
blippy Avatar asked May 02 '16 11:05

blippy


People also ask

What is gsl c++?

The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License. The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting.

What is a gsl owner?

gsl::owner<T*> marks a pointer that has ownership of the referenced object. You should use gsl::owner<T> if you can not use resource handles such as smart pointers or containers. The key point about the owner is that you have to free the resource explicitly.

What is gsl Lite?

gsl-lite is a single-file header-only implementation of the C++ Core Guidelines Support Library originally based on Microsoft GSL and adapted for C++98, C++03.

Where is my gsl library?

The default location of the `gsl' directory is `/usr/local/include/gsl'.


2 Answers

The Guidelines Support Library (see also gsl-lite as an alternative) is a C++ library that implements some of the functions and classes recommended in the C++ Core Guidelines. A document with advice on how to use modern C++. It is worthwhile reading or skimming over the C++ Core Guidelines if you want to improve your use of C++. Using the GSL library is less important, but could be useful if you find yourself implementing code that is already in it. The C++ Core Guidelines have been around for a few years now, so some things, such as string_view, are already available (depending on what version of C++ you are compiling to) and do not require an external library to use.

like image 158
ejgottl Avatar answered Oct 12 '22 00:10

ejgottl


You must use them as suggested in the CppCoreGuidelines.

Read them, understand how it applies to your codebase/programming habits/problems.

Visual Studio 2015 has plugins which help you to check if your code behaves well according to GSL

like image 5
Jepessen Avatar answered Oct 12 '22 00:10

Jepessen