Visual Studio - C programming [closed] - c

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Total NOOB here.
I've noticed that under Visual Studio common C commands are a bit different,
the only example I can think of right now is that VS insists on using scanf_s instead of scanf, but I'm sure there are other quirks.
what I'm asking is, should I be learning, or even working with C on VS and why?
Thanks

MSVC does not insist but only issues warnings, to provoke you into using their own non-standard functions. The warning message from MSVC tells you what to do:
warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use
_CRT_SECURE_NO_WARNINGS
which means putting #define _CRT_SECURE_NO_WARNINGS before any #include files.
I put the following lines before any #include
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <stdio.h> // etcetera
Anyway MSVC does not comply with C standards.

Related

Which windows.h header defines NULL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
This post was edited and submitted for review 7 days ago.
Improve this question
I have to write some Windows code, and I want to separate it from the Linux part as much as possible.
At one point I need to check for NULL in the Windows code, but I don't want to include stdio.h or stdlib.h.
I strongly suspect that NULL is defined somewhere in windows.h, but I can't find the page. I found this, which is interesting, but doesn't tell me what I want to know.
NULL is defined in the standard C header stddef.h, period.
If you run for example gcc/mingw port in Windows, you can just tell any half-decent IDE to find the declaration of NULL and end up in stddef.h where it says #define NULL ((void *)0).
You can also create a source file like this:
// main.c
#include <windows.h>
int main (void)
{}
Then compile with gcc main.c -H. This will expand all header dependencies, so you'll see which header that includes what other headers. You'll get a whole flood of them and you'll notice that stddef.h is indirectly included at some 2-3 different locations.
Conclusion: NULL is not defined by windows.h or any other windows-specific header that you should be including directly.
If you need to use NULL, then the correct approach is to #include <stddef.h> regardless of OS.

Why can't we use if or for loop ,while globally in C [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 months ago.
Improve this question
#include <stdio.h>
if(1)
{
}
int main()
{
printf("Hello world");
return 0;
}
if(1) {} is a (selection) statement (6.8.4) and statements are only allowed in function definitions (6.9.1). See Programming Language - C (draft) for the relevant sections, also refer to the informative Annex A.
We could have had a similar mechanism to sh-scripts where it just goes though the file line-by-line, without main. However, having an agreed-upon entry-point allows compilers to abstract compiling from linking for multi-compilation-unit programmes and libraries.
Dennis Ritchie and Ken Thompson developed it after B. This was based on BCPL, developed by Martin Richards. This had a LET START(), much in the way of Fortran, from The FORTRAN Automatic Coding System:
a basic block is a stretch of program which has one entry point and
one exit point
In that way, going from an sh-script to C is entirely possible, but not the other way around.

Is <windows.h> in collision with "raylib.h" library [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to build a game in C language using raylib library and I wanted to deploy the sleep function that is defined in library. The latter generates a problem in the build of raylib library
Let's say that you have two headers, header1.h and header2.h, both containing a function named foo. Then you can define a new header/source pair:
mynewheader.h:
int header2_foo(int n);
mynewheader.c:
#include <header2.h>
int header2_foo(int n) {
return foo(n);
}
Of course, you can choose any prefix you want, or rename the function completely for that matter. This kind of mimics the namespace feature in C++.
If sleep is the only function you need from Windows.h then use _sleep() from stdlib.h instead. Check this MSDN discussion for further reference.

php extension code must be c89 style [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I wrote a php extension: https://github.com/binpack/binpack-php, it works great and I want to submit this extension to PECL.
But they said that my code is C99 style and PHP except C89 style. I read somethings about C99 and C89.
And figure out some difference:
stdbool.h
inline vs __inline__
I think there are some problem in these 2 files:
https://github.com/binpack/binpack-php/blob/master/bin_pack.c
https://github.com/binpack/binpack-php/blob/master/bin_pack.h
I modified some of my code and used -std=gnu89 to test them. But I am not sure if there are still some problems.
My question is:
How can I test if my code is c89 style?
If anyone can point out the problems in my code, that will be great.
It won't warn about every feature not in C89, but
gcc -Wall -pedantic -std=c89 ...
is a good place to start.

Newbie compiler problems [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm really new in C and I have the Code Blocks compiler. When compiling a really simple program. Sometimes it works but sometimes it doesn't. I'm guessing it has something to do with the things I select when starting a new project. I usually select a console application C language and I have no idea what to select next does anyone know whats going on and how to fix it? This is my code:
#include <stdio>
int main()
{
printf ("hello world !");
getchar ();
return 0;
}
#include <stdio.h> and not #include <stdio>.
Header files in C are saved with .h file extension.
headers in C, by convention, end with .h.
so it should be #include <stdio.h> instead of #include <stdio>.
However, if you are using a C++ compiler, with your file being called foo.cpp, then you can use #include <cstdio> and add using namespace std; to use getchar() function.

Resources