Why CLion don't put Spaces automatically when I finish a line with semicolon? - styles

#include <stdio.h>
int main(){
int a=0;
double b=25.8;
char *s="Hello!";
int a2=45;
if(a==a2){
printf("No!");
}
return 0;
}
It looks just like above, it should be spaces before and after "=" or "==".
But in Jetrains Rider, it works fine, I don't know why CLion cannot.
I think my setting is right, I don't even change it.
My Code Style setting

In order to re-format your code press Ctrl + Alt + L.
You can also find this option under, Code -> Reformat Code.
Another option is to configure clang formatting so that your code gets formatted during build. You can find some information on how to setup clang formatting for a CMake project here:
Add cppcheck and clang-format for a cmake project

Related

problems compiling with gcc and gnu make

The problem arises firstly from the "isfinite" function: (undefined reference to isfinite). From google search I find that I must include "math.h" and write three lines of code, like:
ifdef __linux__
define _finite(v) (__builtin_isfinite(v))
endif
But then, there comes the error: (Make:47 missing endif. Stop).
If I comment out those three lines of code, the error becomes: (<math.h> no such file or directory).
My system is OpenSUSE Leap 15.4; gcc version 7; gnu make version 4.2.1-7.3.2.
I think I have installed all the needed packages. However the errors persist. Any help?
I primarily want to address this part of the question, as the underlying issue has been addressed elsewhere, multiple times:
The problem arises firstly from the "isfinite" function: (undefined reference to isfinite). From google search I find that I must include "math.h" and write three lines of code, like:
ifdef __linux__
define _finite(v) (__builtin_isfinite(v))
endif
I started to write "Google led you astray", but I think it's more likely that you seriously misunderstood what it led you to. And perhaps you happened to choose poor results.
The error message indicates that you put those lines in your makefile, but they are wholly inappropriate for that. Don't put them there.
The lines are C preprocessor directives that have been stripped of their leading # characters. You would use them by restoring the # characters ...
#ifdef __linux__
#define _finite(v) (__builtin_isfinite(v))
#endif
... and putting the resulting lines into one or more of your C source files. BUT DON'T! Those lines are unnecessary and at best unhelpful.
You do need to #include <math.h> in each C source file that contains a call to isfinite(), because that is the header that provides a declaration of the function. Since C99, functions must be declared before they are called (and it was good practice well before then).
Other than that, with GCC and many other traditional-style Unix C compilers, you need to explicitly include the math library in your link when you need any of the functions it provides. That would involve adding -lm to your makefile, at the end of the gcc command that builds the final executable. This is covered in gcc will not properly include math.h, and many other duplicates on this site.

vim clang_complete strange completing bug

consider this simple code:
#include <vector>
#include <string>
using namespace std;
vector<string> vec1;
//vec1. //completion does not work AND break the completion that used to work if left without semicolon.
int main(){
vector<string> vec2;
vec2.push_back("sometext"); //completion works
vec1.push_back("sometext"); //works here too
return 0;
}
When I type "vec2." or "vec1." I am presented with a drop down list of all methods of the string type right after I type the point. So it works here.
Here is how it gets strange:
1) When I do "vec1." in the global scope right before main I am presented with wrong options in the drop down menu (namespace, using, asm, typedef, using, static_assert, extern, etc...). And it cannot find 'push_back' at all ("User defined completion (^U^P^N) Pattern not found)
2) Now, If I leave this line unfinished and forget to put a semicolon I then can't have proper autocompletion inside main() as I did before!
Only plugins I have running are clang_complete and supertab. I tried without supertab and with various _vimrc and .clang_complete settings to no benefit. I'm on win7, llvm/libclang are from official website.
Is it normal that it bugs like that?
The plugin relies completely on libclang to do the completion, which in turn only completes code that's more or less valid (I think it can forgive some errors before the cursor from which the parser is able to recover and code after the cursor can contain more serious errors).
Statements at the global scope are not among valid syntactical constructs of C++. This probably confuses clang's parsing enough to make it return some generic completion list that's not tied to the immediate context.
I think such behaviour is expected for any completion system that employs clang, unless it's explicitly worked around in some way.

How can you use a single quote in an applications name for Inno Setup?

I want to use an application name like:
#define MyAppName "That's all folks"
But #include "modpath.iss" is not compiling out because of the single quote. If I make it That''s all folks, it does work, strangely enough.
I've found your answer here.
It says you need to use {%hex} syntax. hex is the hex value of the character you want to escape, which is 25 in your case. So you need to use:
#define MyAppName "That{%25}s all folks"
I tried it, and it works. Just make sure to update your exe name everywhere if it's in other places in your script.

How to change color of words in Gedit?

I'm writing a code in CUDA C and I'm using Gedit as text editor; when I type some functions like sizeof(), the editor does not color them. In simple words this is what I would like to see:
#include <stdio.h>
#include <stdlib.h>
int main(){
int a = sizeof(int);
return 0;
}
This is instead what i get: sizeof() not colored!! What should i do to modify the color of the function? i have already installed all the plug-in but I don't know what else to do...
CUDA is included by default so simply switch from plain text to CUDA (or any other language) on the right lower part of the window or using the general menu options:
See -> Highlight mode -> CUDA
Gedit uses GtkSourceView for syntax highlight, so you can define your own language if you want. Gedit doesn't highlight some functions like sizeof but still you can add them on the cuda.lang file:
locate gtksourceview | grep /cuda.lang
This link has more information about the definition of a language via .lang files.
EDIT: the c language does include the definition of sizeof, so this should be useful for CUDA, search for keyword on the link!

Automatic syntax/headers in vim for c++ files

I want that whenever i open a new c++ file in vim in linux ( mandriva 2010 ) the following code gets inserted in it automatically :
Default code :
#include <iostream>
using namespace std;
int main()
{
return 0;
}
Is there any way to get it done. also can i bind .py, .pl, .java files with similar things. Moreover i should be able to change the default code for a file.
For customizable headers, code completion, as well as a host of other features specific to C++, try c.vim
One common method for doing this is described at :help template.
Another option would be to use a snippets plugin (like snipMate or UltiSnips). These don't automatically insert the code when you open a new file, but you can create various snippets that will expand to portions of the template you describe and let you fill in the portions that vary (like the header in an #include <...> statement).
Regarding C&C++, muTemplate goes a step further. When creating a new source file (.cpp, .c, ...), if a header file with the same base name is detected in the vicinity, it is automatically included -- in the case the alternate plugin (a.vim) is installed, its detection heuristic is automatically exploited (in some projects, source files and header files are not in the same directory).
NB: files headers (i.e. copyright/VCS stuff can be overridden)

Resources