Build a Visual Studio 2013 project in pure C - c

What is the best way to do this? The templates seem to allow only for C++ (which is basically compatible with C, but not the same.) What is the proper way to do this? (A particular #define or whatever.) Any help would be appreciated.

The solution is simple and easy
You create a new win32 console project
Remove the default .cpp file
Add new .c file as you wish
In Properties, under C/C++ --> All Options, find "Compile as", then select "Compile as C code"
Simple sanity check. This code doesn't work with C++ since "new" is a reserved word for C++.
int new = 10;

Related

How to recompile a '.h file' on mac?

I am using a tool that has been written in C or C++.
https://github.com/kern-lab/discoal
I've never used C myself. In one of the files in discoal.h, I want to change: #define MAXSITES 220020 to #define MAXSITES 1100000. The tool manual says that I would have change the MAXSITES define in discoal.h and then recompile. How do I recompile?
I have never used C language before and I am not a Computer science student therefore, do not have much experience in programming either. Therefore, if you could let me know the command to recompile that'll be great. I've provided a link to that tool in case you want to look at the files.
Open a terminal, cd to the directory where the Makefile is, and type make, then hit Enter.
Prerequisites: A C compiler, which comes with Xcode on a Mac, as #Shawn commented.

Ignore C++ keywords in ANSI-C project header files - Netbeans IDE

I have created a C-Application project and I want to use names such as new or delete in my project but I cannot due to their being reserved keywords in C++. How can I instruct Netbeans IDE to ignore C++ specific keywords ?
EDIT: Using _new or _delete would be a sloppy workaround and it is not what I am looking for.
EDIT2: This problem occurs only in *.h header files. When I type new or delete inside a *.c, file it does not get highlighted.
It is always a good idea to avoid reusing keywords, even if they are not keywords in the dialect/version that you are currently using - you may wish, or have, to update the tool chain later.
Just use New and Delete instead or mynew & mydelete.
A keyword in C++ that is not a keyword in C can be used as an identifier in C.
In my VC2008 IDE the editor still colors it as a reserved word, but it isn't.
I have created a C-Application project and I want to use names such as
new or delete in my project but I cannot due to their being reserved
keywords in C++. How can I instruct Netbeans IDE to ignore C++
specific keywords ?
If you have created a C project, this isn't an issue. It seems you have a C++ project instead. What file ending are you using? .c should work without problems -- even syntax coloring will not highlight new / delete for C files.
Just for testing you can create a simple project, with just a main.c and test a code with eg. int new variable.
but I cannot due to their being reserved keywords in C++
Can you give us some more details on this?

How can I get Eclipse to index code inside #ifdef .... #endif

I'm using eclipse to work on some c code and it is not indexing code inside conditional compilation blocks like this:
#ifdef USE_FEATURE_A
int feature_a(...) {
some = code(here);
}
#endif
How can I get eclipse to index the feature_a function?
You could tell eclipse that USE_FEATURE_A is defined. Open your project properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click the "Add" button and put USE_FEATURE_A in the name feild and click OK.
Note: this will cause it not to index any #else sides to your preprocessor stuff... so unless they are all like the one in question you can't AFAIK, but if they are they you're good. (Eclipse contains a C preprocessor that it uses to analyize your code all the stuff above does is essentially the same as adding -DUSE_FEATURE_A to your command line so Eclipse's preprocessor will behave differently from the one in your compiler)
This is an easier and in my opinion more elegant solution to the one selected as the solution:
If someone has the same problem (as I had), this can (now?) easily be solved by going to Window->Preference->C/C++/Indexer and enable "Index all header variants".
Then click Project->C/C++ Indexer->rebuild and clean and build your project. This should resolve all error originating from preprocessor commands.
For what it's worth, getting eclipse to parse conditionally compiled code is much harder to do than would appear at first glance. I found a paper on by IBM from 2007 where they said they will prioritize for the "next release".
Handling Conditional Compilation in CDT's Core
I had this same problem, but the code conditionally eliminated by preprocessing was perfectly valid c code and I wanted it formatted... This was my solution:
1) Global find/replace of #if to #JUNKif
2) Ctrl-Shift-F to reformat the source
3) Another global find/replace of #JUNKif to #if
One way to index code under flag in Eclipse(Kepler) c/c++Editor.
You can enable the compilation flags in Eclipse editor so that code under them can be indexed.
Properties > Preprocessor Include Paths > CDT User settings Entries
Click on ADD and add the Preprocessor Macro and you can specify its value.
Best way I guess is to use the Indexer option : Project Properties>C/C++ General>Indexer.
You can choose Enable project specific settings
I prefer choosing "Use active build configuration" so that all files which are actually built in the project are indexed.
Anyhow you can also choose to index all files in the project even if they are not included in the build ...

Visual Studio: Create a Hello World app in C?

How can I create a basic C app in Visual Studio, be it 2010 Ultimate or 2008 Professional? I have searched through the project templates, and can find plenty for C++, but none for C.
(I'm hoping that the compiler and debugger will be built in.)
New project/Win32 Console Application/Empty project.
Add a file called "hello.c" (important that it's .c)
Type out a basic hello-world:
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
Compile, execute... PROFIT!
Visual Studio doesn't have a separate compiler for C, it uses the C++ compiler for C code. You can tell it to restrict itself to legal C syntax by using a compiler switch or by renaming the .cpp file to .c
Edit: I'm still using 2005 on this machine, so it might not be in the same place, but try this
Right click on the main.cpp in the solution explorer pane (on the right).
Choose Properties (bottom of the menu)
Open up the C/C++ group of properties
choose Advanced page
Change "Compile As" property to "Compile as C Code (/TC)"
In addition to changing the file extension, you may need to change the compiler settings:
Settintgs of Application->C/C++->addition->compiler such...
You must take /TC for basic C and /TP for C++.
https://msdn.microsoft.com/ru-ru/library/032xwy55.aspx
Good Luck.

C programming in Visual Studio 2008

Do you know if it's possible to programm c (not c++) in Visual Studio 2008? If yes then how? I haven't found any component for that.
Regards.
Just save the file with .c extension instead of .cpp and it will compile as C instead of C++. To be extra cautious, you can go to the project settings, under "Project -> Properties -> Configuration Properties -> C/C++ -> Advanced", make sure that "Compile As" says "Compile as C code (/TC)".
As long as your source file has the .c extension, Microsoft C++ compiler will compile in C-mode.
In addition, the /Tc<source filename> switch can be used to force compilation of a specific file in C mode, and the /TC switch can be used to force C mode for all files. For C++, it's /Tp and /TP respectively.
You can specify any compiler you'd like in VisualStudio; therefore, if there's a specific C compiler you'd like to use, it will handle it.
If you want to make a .c program in Visual Studio 2008:
Goto>>File>>New>>Project
Choose "Visual C++" in the left column, then in the right column, select "Win 32 Console Application".
Write file name as:
"Any_Name.c"
Here you can now create a C program:
Create source file
To compile, press ctrl+shift+B
To run, press F5
It does not work because C++ precompiled headers, so the solution is select project-properties-c/c++-precompiled headers
Then select Not Using Precompiled Headers

Resources