From the blog

Enhancing the CMake Targets View in Visual Studio

Enhancing the CMake Targets View in Visual Studio Sinem Akinci September 20th, 20231 2 The CMake Targets View in Visual Studio is a view that allows you to visualize your CMake project structure by the CMake targets and build specified target libraries and executables. To make this view more usable, we have implemented a few new improvements to make it easier than ever to navigate your CMake targets. This includes improved navigation to the CMake Targets View, a new, more simplified CMake Targets View, and the ability to exclude specified CMake items from the Targets View. Additionally, we have future planned work in the near-term to allow users to customize this view to their desired configuration. Download the latest preview version of Visual Studio to try out the new updates for the CMake Targets View. Get to your CMake Targets View Quicker Than Ever Customers have reported that it can be cumbersome to switch between CMake Targets View and the Solution Explorer. To address this, we have implemented new entry points to open the CMake Targets View much more quickly. Switch to your CMake Targets View from Solution Explorer Now, you can right-click anywhere in your Solution Explorer and simply navigate to the CMake Targets View from the context menu. Open the CMake Targets View from the ‘View’ Dropdown Menu You can also access the CMake Targets View globally at any point in your CMake projects by selecting from the View dropdown. Simplify your Source Navigation The CMake Targets View has been further simplified so that users don’t have to click through folders without buildable executables to get to their desired target.   Define Items to Exclude from View You can now define in your VSWorkspaceSettings.json items to exclude from the CMake Targets View using the new CMakeTargetsViewExcludedItems field. The CMakeTargetsViewExcludedItems field is an array of strings. The field supports the following syntax and identifiers: Supported “identifiers”: CMakeProject, CMakeTarget, CMakeReference, CMakeFolder, CMakeFile. Syntax for the CMakeTargetsViewExcludedItems is the following: : This will specify any identifier with the specified name. For example, CMakeTarget:app. Any CMake targets with the name “app” anywhere in the CMake Targets View will be excluded. Additionally, if you want to specify specific items to be excluded, you can use a – to chain declarations together::-:… For example, CMakeProject:thirdPartyDependency-CMakeTarget:irrelevantThirdParty. Example usage in a VSWorkspaceSettings.json: {   “CMakeTargetsViewExcludedItems”: [     “CMakeTarget:-CMakeFile:*”, “CMakeTarget-*-CMakeFile:*”, “CMakeTarget:-*-*-CMakeFile:*” } What’s Coming Next? We are continuing to develop the CMake Targets View to allow for further customization of this view based on customer feedback. Stay tuned for the latest updates as these ship in the future! We are planning to give users the ability to filter their CMake Targets view by type of target, project, etc. Users will be able to dynamically pin and unpin their most used targets to the top of the CMake Targets View. We are using this suggestion ticket to track any other requests you may have for improvements to the CMake Targets View to meet your CMake needs: CMake Targets View Suggestions – Developer Community (visualstudio.com) Anything else? You can also find us on Twitter (@VisualC) or via email at visualcpp@microsoft.com. To open a bug, please see Visual Studio Feedback. Sinem Akinci Program Manager II, Visual C++ Team Follow

Read More

Learn How To Use Integer Literals And The Deprecated Attribute In C++

Hello fellow C++ Developers. Since January we have released many new posts covering the features of the C++11 standard. These features are mostly done, and this week we start on describing C++14 features. We have five more beginners to professional-level topics in modern C++. C++ evolves and refines itself even further with the release of each new C++ standard. C++14 came with a new deprecated attribute feature to allow marking an entity as deprecated – potentially obsolete and best avoided. We explain what deprecated means and how to use the deprecated attribute in C++. In another post, we explain why the gets function was deprecated in C++11 and eventually removed altogether in C++14. We teach integer literals, and binary literals that come with C++14. There is also a great new feature, digit separators that makes it easy to see integer values in coding, and we explain how to use it in different integer types. Our educational LearnCPlusPlus.org site has a whole bunch of new and unique posts with examples suitable for everyone from beginners to professionals alike. It is growing well thanks to you, and we have many new readers, thanks to your support! The site features a plethora of posts that are great for learning the features of modern C++ compilers with very simple explanations and examples. RAD Studio’s C++ Builder, Delphi, and their free community editions C++ Builder CE, and Delphi CE are a real force for modern application development. Table of Contents Where I can I learn C++ and test these examples with a free C++ compiler? How to use modern C++ with C++ Builder? How to learn modern C++ for free using C++ Builder? Do you want to know some news about C++ Builder 12? Where I can I learn C++ and test these examples with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great, easy to understand examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional version of C++ Builder  or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How to use modern C++ with C++ Builder? C++ is very strong in every aspect of modern programming and evolves and refines itself even further with the release of each new C++ standard. While there are many new additions there are some features that are found not useful or ‘dangerous’ in programming, thus the C++ community offers its deprecation in the next released C++ standard and then it is generally removed in the following standard. C++14 came with a new deprecated attribute feature to allow marking an entity as deprecated – potentially obsolete and best avoided. In the first post, we will explain what deprecated means and how can we use the [[deprecated]] and __declspec(deprecated) attributes in modern C++. Modern C++ has a lot of useful functions […]

Read More

Cum să înbunătățești în 2023 productivitatea echipei de dezvoltare cu GitLab Duo

Află cum GitLab Duo te poate ajuta să dezvolți software mai sigur, mai rapid și mai eficient, beneficiind de scanarea automată a vulnerabilităților de cod, aplicarea politicilor de securitate și auditare, generarea și optimizarea automată a codului, sugerarea și aplicarea celor mai bune practici și standarde de codare, oferirea de feedback și recomandări personalizate, asigurarea unei autentificări sigure și ușoare a dezvoltatorilor, și multe altele. De asemenea, află cum poți să testezi gratuit pentru 30 de zile fără a fi necesar datele cardului bancar soluția GitLab Ultimate care include GitLab Duo. Introducere: Provocările actuale cu care se confruntă echipele de dezvoltare software Dezvoltarea software este un domeniu în continuă evoluție, care implică o serie de provocări pentru echipele care lucrează la proiecte complexe și inovatoare. Una dintre aceste provocări este de a asigura securitatea codului, care este esențială pentru a preveni atacurile cibernetice, a respecta reglementările și a proteja datele sensibile. O altă provocare este de a optimiza viteza și calitatea livrării codului, care sunt cruciale pentru a satisface cerințele clienților, a menține competitivitatea și a reduce costurile. Pentru a face față acestor provocări, echipele de dezvoltare au nevoie de instrumente și soluții care să le ajute să gestioneze eficient ciclul de viață al software-ului, de la planificare, la codare, la testare, la implementare și la monitorizare. În acest articol, vom prezenta cum GitLab, o platformă integrată pentru gestionarea ciclului de viață al software-ului, oferă funcționalități asistate de inteligență artificială (AI) care pot îmbunătăți securitatea și productivitatea echipei tale de dezvoltare. Vom arăta cum GitLab folosește AI pentru a detecta și remedia vulnerabilitățile de cod, pentru a genera și optimiza automat codul, pentru a sugera și aplica cele mai bune practici și standarde de codare, și pentru a oferi feedback și recomandări personalizate. De asemenea, vom discuta despre beneficiile și avantajele pe care le aduce GitLab prin integrarea AI în platforma sa, precum și despre planurile și viziunea sa pentru viitor. GitLab: soluția integrată pentru automatizarea livrării software. GitLab este soluția integrată pentru automatizarea livrării software, care îți permite să te concentrezi pe crearea de valoare, nu pe menținerea unui lanț de instrumente fragil și complex. Cu GitLab, poți să livrezi software mai rapid, mai sigur și mai eficient. Codezi mai ușor și mai corect, folosind funcționalitățile de repository-uri Git, editor Web IDE, sugestii de cod și recenzii de cod. Astfel, poți să scrii cod în orice limbaj de programare, să editezi cod direct în browser, să primești recomandări relevante în timp ce tastezi, și să discuți și să îmbunătățești codul înainte de a fi integrat în branch-ul principal. Testezi codul tău într-un mod automat și continuu, folosind funcționalitățile de integrare continuă (CI), Auto DevOps, pipeline-uri, job-uri și artefacte. Astfel, poți să rulezi teste automate pentru a verifica calitatea și funcționalitatea codului tău, să beneficiezi de o configurare automată a CI/CD pentru proiectele tale, să vizualizezi și să controlezi fluxul de lucru al codului tău, și să stochezi și să accesezi fișierele generate de teste. Implementezi codul tău într-un mod rapid și sigur, folosind funcționalitățile de livrare continuă (CD), medii, pagini și serverless. Astfel, poți să livrezi codul tău în producție fără întârzieri sau intervenții manuale, să creezi și să gestionezi medii de dezvoltare izolate pentru fiecare branch sau cerere de unire, să publici site-uri web statice direct din GitLab, și […]

Read More

What’s New for the Remote File Explorer in Visual Studio

What’s New for the Remote File Explorer in Visual Studio Sinem Akinci September 18th, 20233 2 The Remote File Explorer gives you the capability to access your files and folders on your remote machines that you are connected to through the Connection Manager in Visual Studio, without having to leave the IDE. Since we last spoke, the team has implemented new features to further enhance your remote file workflows by listening to your direct feedback.  Download the latest preview version of Visual Studio to access the new updates for the Remote File Explorer and give it a try. Background To access the Remote File Explorer, navigate to View > Remote File Explorer after downloading through the Linux and Embedded Workflow in Visual Studio. It will also now automatically open when you open a cross-platform C++ project (vcxproj for Linux or CMake project with at least one configuration in CMake Presets with a remote SSH target). Our initial announcement can be viewed here, which goes into browsing, uploading, and downloading files. To learn more about how to connect to a remote machine through the Connection manager, please see these instructions. Now, you can view and edit these files from Visual Studio, as well as search for files through the top bar. Additionally, with the new enhanced toolbar, you are more empowered than ever to quickly perform actions on your files. Search your Files You can now search through your files and folders on your remote machine using the top bar in the Remote File Explorer. After searching, you can then right-click on any result and select “Go to remote path” to then navigate to that result’s remote path location in the Remote File Explorer. View and Edit your Files The Remote File Explorer now allows you to view and edit files on your remote machine from Visual Studio, just like you would any other file in the Solution Explorer. The Remote File Explorer will also automatically detect if your remote files have any changes that occurred so that you can be certain when in remote workflows. Home and Settings Icons New icons have been added to the toolbar of the Remote File Explorer to make it easier than ever to navigate and perform actions. Clicking the home icon quickly navigates the user back to the root node. Clicking on the settings icon opens the Remote File Explorer settings that allows you to configure your Remote File Explorer. What’s Next? To improve your end-to-end remote workflows, we are planning to further integrate this feature with the Integrated Terminal and other potential remote workflows. We would love to hear from you how you would use this feature to further shape our backlog and other planned enhancements. Please reach out to us via email if you would like to chat or we have an open feedback ticket here. Send us more feedback! We hope the latest updates to the Remote File Explorer will further empower you in your remote workflows. Please let us know your thoughts and any other ideas you may have for the feature. The comments below are open and we also have a Visual Studio Feedback ticket open to track any requests that you can comment on. You can also find us on Twitter (@VisualC) or via email at visualcpp@microsoft.com. To open a bug, […]

Read More

Learn How To Use Generic Lambdas In Modern C++

Lambda Expressions allow users to write an inline expression that can be used for short snippets of code in your C++ app which are not going to be reused and don’t require naming. The Lambda Expression construct is introduced in C++ 11 and further developed in the C++14, C++17, and C++20 standards. In C++14, lambda expressions are improved by the generalized lambda (generic lambda) or initialized lambda feature, and in this post, we remember what lambda is and explain what a generic lambda is, and how we can use it. What is a lambda expression in modern C++? A Lambda Expression defines an anonymous function or a closure at the point where it is used. You can think of a lambda expression as an unnamed function (that’s why it’s called “anonymous”). Lambda expressions help make code cleaner, and more concise and allow you to see behavior inline where it’s defined instead of referring to an external method, like a function. Lambda Expressions are an expression that returns a function object, and they are assignable to a variable whose data type is usually auto and defines a function object. The syntax for a lambda expression consists of specific punctuation with = [ ] ( ) { … } series.  If you are new to lambdas or want to know more about it, please check these two posts that we released before. How to use a lambda expression in modern C++ Simple Syntax of Lambda Expression is;   Datatype Lambda Expression = [Capture Clause] (Parameter List) -> Return Type { Body }   Now let’s see this syntax in an example. We will define a lambda expression to combine datatypes;   int add_integers = []( int a, int b ) {    return a + b; };   and we can use lambda as below,   int x = add_integers( 10, 20 );   What is the generic lambda expression in modern C++? Before C++14, lambda function parameters need to be declared with concrete types, as in the given example above. C++14 has a new generic lambda feature that allows lambda function parameters to be declared with the auto-type specifier. Generalized lambdas can be defined with the auto keyword that comes with C++11 before. Let’s take the same integer example above, we can define a generic lambda with the auto keyword as below,   auto add_things = []( auto a, auto b ) {    return a + b; };   Generic lambdas are essentially templated functor lambdas. In example, the code above is equivalent to this code,   struct {    template      auto operator()( T x, U y ) const { return x + y; } } add_things{};   How to use generic lambdas in modern C++ We can use this lambda with int type,   int x = add_things( 10, 20 );   or we can use with float type,   float x = add_things( 10.f, 20.f );   or we can use it with bool, char, double, long long double,…etc types. This is why it is called as ‘generalized‘, it is a general form that we can use with any types. Very useful and powerful. Note that, auto type deduction is added into C++14, and generic lambdas feature follow the rules of template argument deduction. Is there an example of how to use generic lambdas […]

Read More

Learn How To Use Binary Literals In Modern C++

C++14 brings us fewer but useful features to modern C++ than the standards preceding it. The creator of C++, Bjarne Stroustrup says that improvements in C++14 were deliberately lower in quantity compared to C++11. One of the small but useful features is the introduction of “Binary Literals”. C++14 comes with the Binary Literals feature, and in this post, we explain how we can use binary bits.  Learn how to use binary literals in modern C++ A binary literal is an integer literal that your binary number begins with 0b or 0B and consists of a sequence of binary digits (base two). It is defined in  and provides a convenient way to represent a binary base-2 number (1 and 0), useful for the developers in IDE, and useful to compilers that understand it is a binary value. Here is a simple example of how we can use it.   #include   int main(){ int b1 = 0b00111011; }   Is there a simple example about how to use binary literals in modern C++? We can use it with digital separators, which are another feature of C++. Here is an example, this time we used constants.   const int b8 = 0b1111‘0000; const int b16 = 0b1111′0000‘1111’0000; const int b32 = 0b1111‘0000’1111‘0000’1111‘0000’1111‘0000;   Note that, we can NOT use digital separator after the 0b literal as below.   const int b8 = 0b‘1111’0000;   Is there a full example about how to use binary literals in modern C++? Here is a full example about how to use binary literals in C++. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21   #include #include   int main() { int b = 0b00111011;   int b8 = 0b1111‘0000; int b16 = 0b1111′0000‘1111’0000; int b32 = 0b1111‘0000’1111‘0000’1111‘0000’1111‘0000;   std::cout

Read More

Learn To Use Digit Separators In Modern C++

In the history of modern C++, the C++14 standard brings us some very useful features. C++14 comes with the digit seperators feature. In C++14 and above, we can use the digit separator  to separate integer numbers. In this post, we explain, how to use digit separators in examples, How can I use use digit separators in modern C++? In C++14, there is a new Digit Separators feature. The digit separator is a single-quote character ‘ that can be used within a numeric literal for aesthetic readability. When you use digit separators, it does not affect the numeric value, but it is very useful when you are using bigger or longer digital numbers. It can be used with int, long int, long long int, float, double, auto, etc.  Here is a simple example to digit separators.   long long int LL = 123‘456’789;   Is there a full example about to use digit separators in modern C++ Here is a full example about to use digit separators in modern C++. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23   #include #include   int main() { int x = 1‘024;   unsigned int m = 128′000‘000;   long double pi = 3.141′592‘653’589;   long long int LL = 123‘456’789;   std::cout

Read More

Learn The Useful Integer Literals In Modern C++

A programming language consists of a lot of expressions in our source code. One of elements of expressions in C++ are literals. A more specific type of literal is Integer Literals. Integer literals are primary expressions that allow values of integer types (i.e., decimal, octal, hexadecimal) to be used in expressions directly. They are further improved by the boolean literals (binary digits) in C++14. In this post, we will explain and list the types of integer literals available to us in modern C++. What is integer literal in modern C++? Integer Literals in C++ are primary expressions that are used to indicate the base or the type of an integer value. They allow values of integer types to be used in expressions directly. They are further improved by the addition of boolean literals in C++ 14. We can categorize integer literals into two groups: Prefixes and Suffixes. What is the prefix integer literal in modern C++? Prefix Integer Literals are used to indicate the numeric base of the literal. For example, the prefix 0x indicates a hexadecimal base (i.e. value 0x10 indicates the value of 16). Here are the prefixes for integer literals (integer-prefix). Prefix Literal Base Example -no prefix- Decimal Literals Base 10 1024 0 (zero) Octa Literals Base 8 048 0x or 0X Hex Literals Base 16 0xFF 0b or 0B Binary Literals Base 2 0b01010111 Here are simple examples to prefix integer literals:   int d = 1024; // decimal int o = 076; // octal int x = 0xFF22CC; // hexadecimal int b = 0b10101111; // binary (C++14)   What is the suffix integer literal in modern C++? Suffix Integer Literals are used to indicate the type. For example, the suffix LL indicates the value is for the long long integer (i.e. value 98765432109876LL indicates it is a long long integer). When we use suffix, that means this type of the integer literal is the first type in which the value can fit, and there are other decimal types from the list of types that depends on which numeric base and suffix. Here are the suffixes for integer literals (integer-suffix), Suffix Decimal Type Other Decimal Types -no suffix- intlong intlong long int intunsigned intlong intunsigned long intlong long intunsigned long long int l or L long intunsigned long intlong long int long intunsigned long intlong long intunsigned long long int ll or LL long long int long long intunsigned long long int z or Z (C++23) the signed version of std::size_t the signed version of std::size_t std::size_t u or U unsigned intunsigned long intunsigned long long int unsigned intunsigned long intunsigned long long int ul or UL unsigned long intunsigned long long int unsigned long intunsigned long long int ull or ULL unsigned long long int unsigned long long int uz or UZ (C++23) std::size_t  std::size_t  Here are simple examples of how to suffix integer literals in C++.   int i1 = 2048; long i2 = 2048L; // or l long long i3 = 2048LL;  // or ll   unsigned int u1 = 2048u; // or U unsigned long int u2 = 2048ul; // or UL unsigned long long int u3 = 2048ull; // or ULL   The C++23 feature can be tested with this __cpp_size_t_suffix if definition as we show below.   #if __cpp_size_t_suffix >= 202011L // (C++23 feature) auto size1 = 0z; // or Z auto size2 = 40uz; // or UZ static_assert( std::is_same_v ); static_assert( std::is_same_v ); #endif   Is there a full example about integer literals in modern C++? Here is a full example of how to use integer literals that uses prefixes and suffixes in modern C++. 1 2 3 4 5 6 7 8 9 10 11 […]

Read More

Why Was The Gets Function Removed In C++14?

Modern C++ has a lot of useful functions coming from C. One of them was the gets() function that we use to get string inputs and that we were able to use in C++11 or earlier. In C++14, the gets function was removed, while fgets or other input functions remain there. If you have older C++ code that uses the gets() functions your C++14 version compiler will not compile it. Why was the gets function removed? In this post, we explain what the gets function is, why the std::gets function was removed by the C++14 standards, and how can we use similar functions or alternatives to the gets() function. What was the gets() function considered dangerous in C++? In C++11 and before, we were able to gets function. The std::gets function was first defined in the C language and was available in C++11 and earlier. The gets function reads inputs into a given char string. When a char string has a newline character, it is considered the end of input, and an end-of-file condition occurs. The return value is captured on success, or a null pointer on failure. The syntax below is deprecated in C++11 and removed in C++14.   char* gets( char* str );   Here is an example of a dangerous gets function,   #include #include   int main() {    char str[8];      gets(str);      printf(str: %s“, str);      return 0; }   Why was the std::gets function removed In C++14? According to C++14 document N4140 (Page 1237), the “use of gets is considered dangerous“, because the std::gets function does not check the bounds of a char array. This makes gets extremely vulnerable to buffer-overflow attacks. In other words, the std::gets function cannot be used safely. The std::gets() function was deprecated in C++11 and removed completely in C++14. If you REALLY need to use it in your apps, then there are some alternatives – for example you can use std::fgets(). If we use gets(), it is impossible to tell without knowing the data in advance how many characters will be read, and because std:: gets() will continue to store characters past the end of the buffer, it is extremely ‘dangerous’ to use.  Here is the definition from C++14 (Document Number: N4140, Page 1237).   C.3.4 Clause 27: input/output library Change: gets is not defined. Rationale: Use of gets is considered dangerous. Effect on original feature: Valid C++ 2011 code that uses the gets function may fail to compile in this International Standard.   They added a note to [c.files] saying that the C function gets() is not part of C++ and they removed gets from tables 134 and 153. We should note that there are some compilers that still support the gets() function. The gets function may be only used if the program runs in an environment that restricts inputs from stdin. Are there any alternatives to the std::gets function in modern C++? First of all, never use std::gets() function, use std::fgets() instead or other input methods of modern C++. There is no way to check the size of input before we store data to that variable. If you have older C++ code that uses the gets function and you want to modernize it, you can use std::fgets() as shown below. 1 2 3 4 5 […]

Read More

What Does Deprecated Mean And How To Use Deprecated Attribute In C++?

C++ is very strong in every aspect of modern programming and evolves and refines itself even further with the release of each new C++ standard. While there are many new additions there are some features that are found not useful or dangerous in programming, thus the community offers its deprecation in the next standard and then it is generally removed in the following standard. C++14 came with a new deprecated attribute feature to allow marking an entity as deprecated – potentially obsolete and best avoided. In this post, we will explain what deprecated means and how can we use the [[deprecated]] and __declspec(deprecated) attributes in modern C++. What does deprecated mean in C++? Deprecation is the process of taking an older code part (a method, function, or property) and marking it as no longer being useful within the current version of the programming codebase (generally it is a standard, i.e. C++11, C++14) . It also flags that the deprecated feature will probably be removed in the next version of C++. Often this is because a feature or function has been found to be ‘dangerous’ or has been superseded or obsoleted by newer code. The deprecated attribute does not mean it is immediately removed from that C++ version (a standard or a library) because doing so may cause regression errors. Generally, a deprecated feature is going to be removed in the next version or standard. For example, the gets() function was found to have potentially dangerous (undesirable) behavior and it was deprecated in the C++11 standard and removed in the C++14 standard. Briefly, deprecated means, that part of code is considered outdated and not recommended to use, and that the keyword, feature, or function will probably be removed in a subsequent C++ standard. How can we use the deprecated attribute in C++? C++14, came with a new deprecated attribute feature to allow marking an entity deprecated, There are two options to declare something as deprecated. We can use [[deprecated]] and __declspec(deprecated) attributes. The deprecated attribute is very useful to mark your older functions that probably will be removed. When you are working on a code base which you share with other developers it is useful for them to know that a section of code they are viewing is potentially outdated or will be removed – and the deprecated attribute is the best way to do that. While this is necessary for compiler developers (i.e. C++ Builder, GCC, Visual C++), it is also very desirable for library developers. If you find any code that will be removed in the next version, first, you can release a version that has the affected code part marked as deprecated. Then in the next release, you can remove it from your library. This is the modern way of professional programming. The [[deprecated]] attribute allows marking the part of the code entity deprecated, which means it is still available to use but gives a warning from the compiler that the use of the code section is deprecated, it is discouraged and may allow ‘dangerous’ errors on runtime. Generally, a warning message is printed during compilation, and in the new modern IDEs there are warning icons displayed too as shown in the example below. Is there a simple example of how to use the deprecated attribute in C++? To deprecate a function, we can use […]

Read More