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

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.

Related

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.

How to use regex in C/Where to find the files? [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 1 year ago.
Improve this question
I want to use regex and I saw that the POSIX regular expression library provides functions but how do I include the library? Where to find the files? I googled a lot and did not find any manual.
Can anyone help me by providing a manual or a link to a manual? I am using Visual Studio Code
C by itself doesn't have regex, but there are multiple libraries providing this functionality, like:
PCRE and PCRE2 - http://www.pcre.org/
libgnurx - https://github.com/TimothyGu/libgnurx
TRE - http://laurikari.net/tre/about/
sregex - https://github.com/openresty/sregex
slre - https://github.com/cesanta/slre
liblightgrep - https://github.com/strozfriedberg/liblightgrep
RxSpencer - https://github.com/garyhouston/rxspencer
RE2 - https://github.com/google/re2/
Oniguruma - https://github.com/kkos/oniguruma
Onigmo - https://github.com/k-takata/Onigmo
Hyperscan - https://www.hyperscan.io/
And there are probably more regex libraries out there.
I have been able to compile all of the above from source for Windows using MinGW-w64.
Most commonly used are PCRE, PCRE2, libgnurx, but Oniguruma and Hyperscan are interesting alternatives.
If you're using C++ there is also std::regex or boost::regex.

Making a portable C library interface: extern declaration vs function pointers [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 2 years ago.
Improve this question
I'm building a portable C library that needs to interact with a user-defined peripheral.
Here's an example,
My library needs to use a user-defined putc() and a getc().
To my understanding, there's two way to do this cleanly:
Using an "install" function that requires user to define interface with function pointers
// Inside mylib.h
typedef int (*mylib_port_putc)(char c);
typedef int (*mylib_port_getc)(char *c);
void mylib_install_port(mylib_port_putc, mylib_port_getc);
Using the extern keyword to let the user decide where to define the interfaces.
// Inside mylib.h
extern int mylib_port_putc(char c);
extern int mylib_port_getc(char *c);
What's the best way to do this?
I understand that "best" is difficult to define, but your opinion would be greatly appreciated.
EDIT:
I disagree with the StackOverflow maintainers to flag this question as inappropriate. I don't think this website should be limited to "how do I do X?" questions. I understand that asking for opinions will probably not generate a clear answer, but, to me, this is what mentorship looks like.
When you're starting, there's a lot of value in studying knowledgeable people debating tradeoffs.
Sorry for the rent. I know your job is hard. Happy holidays.
I think that the only correct way is the first -
you provide a library initialize(...) function for registering user callback functions - port_putc, port_getc, maybe also callbacks for you library logging, etc.
Such an approach is flexible, and very common.
In the second case, you require the library users to define 2 functions with predefined names in their code.
What happens if he didn't?

How to clear terminal in C without using #include? [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 2 years ago.
Improve this question
I want to clear terminal in C without using #include.
Here is my code:
int printf(const char *format, ...);
int main()
{
printf("%c2J", 27);
}
You likely won't be able to clear a terminal without using functions in the standard library, but probably the closest thing would be to use ANSI escape sequences, which might work depending on your terminal.
You'll have to output \x1b[2J (probably followed by \x1b[H). These are the ANSI terminal escape sequences for clearing the screen and repositioning the cursor in the upper left "home" position, respectively.
#include <stdio.h>
int main(void) {
printf("\x1b[2J\x1b[H");
return 0;
}
Please note that even if you specify the function prototype for printf(), as you have done above, you are still using the standard library and not making your own. I can only think of one reason you'd ever want to do that: to make a quine fit on one line.
If you want to write your own function you should not be using the standatd library. Invlude does not matter as .h files are not libraries. You should compile the code with -nostdlib option and write your own function.
In your code you simply use the standard library function - not your own one.

Which naming convention should I use for a struct? [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 9 years ago.
Improve this question
In plain C, I will name a struct like this:
struct MyStruct
{
int something;
};
But, since I'm now programming under Windows, I want my code to be very consistent in which refers to naming conventions. So, my variables are now named using mixedCase instead of lower_case and my functions are now using CapWords. I have seen some structs with all capital letters, but I don't like this very much because I reserve that for constants and macros.
Thanks.
Check out this link if you want a reference on Naming Conventions in C.
As long as you're consistent with using CamelCase of under_score conventions for whatever purpose, it doesn't really matter.
What are the most common naming conventions in C?
Here is a similar question:
Naming convention for Win32/MFC with C++
MSDN naming guideline locates at http://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx
Struct naming convention is described at http://msdn.microsoft.com/en-us/library/ms229040(v=vs.110).aspx

Resources