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.
Related
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.
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 5 years ago.
Improve this question
important thing: -D does not apply here.
Is it possible to declare macros that appear in every compilation (much like predefined macros) in some dynamic manner (meaning I'm lazy to recompile gcc)? or do I have to recompile my gcc? Should I have to recompile, how do I specify my predefined macros?
You might consider providing some (or improving yours) spec file.
You could patch the gcc/c-family/c-cppbuiltin.c file of the source code of GCC.
You could code then use a GCC plugin defining additional predefined macros.
But I am sure it is a very bad idea; I recommend instead passing explicitly some -D flag to your compiler; your question smells badly as some XY problem. You need to motivate your question.
You could instead organize your PATH variable and add appropriately some gcc shell script adding that -DMACRO option and explicitly invoking e.g. /usr/bin/gcc with it.
On Linux you can
use an alias:
alias gcc="gcc -DMACRO1 -DMACRO2"
Copy old /usr/bin/gcc to /usr/bin/gcc.original. Make your own shell script and name it /usr/bin/gcc, inside which you have
exec /usr/bin/gcc.original -DMACRO1 -DMACRO2 "$#"
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 6 years ago.
Improve this question
The C11 standard Annex K defines a bunch of new safer string functions, all suffixed by _s (e.g. strcpy_s).
Do you know when these new functions will become available in the GNU C library glibc?
So far you have to fall back to a third party library like safec.
Do you know when these new functions will become available in the GNU C library glibc?
When someone contributes an implementation and convinces GLIBC maintainers that these functions are good to have.
Relevant thread from 2007.
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.
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 5 years ago.
Improve this question
I can't find how to write comments in C. I mean I know about // and /* */, what I mean is where can I find good practices? Like if I have a function, how do I write the #param variable is the value bla bla, like it is done in Java?
Are there any standards for this? Or can I just do it like I do it in Java?
There are many different standards, if you want to generate documentation, try doxygen
You can use javadoc standard and then use doxygen that understands javadoc to generate a documentation.
In doxygen I recommend using the option JAVADOC_AUTOBRIEF set to YES. If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the first line (until the first dot) of a Javadoc-style comment as the brief description.
Example for a class definition:
/**
* A brief description. A more elaborate class description
* #param bool somebool a boolean argument.
* #see Test()
* #return The test results
*/
(Some more examples in the doxygen manual)
Installation is really simple, there is a GUI and a nice graphical visualisation available with:
apt-get install doxygen doxygen-gui graphviz
Run the gui calling doxywizard and use the Wizard settings, only JAVADOC_AUTOBRIEF has to be set there in "Expert" settings.
There are no standards follow the standard which your company mandates.
A popular way to create documentation from projects is to use doxygen.
An option is to use the doxygen format of writing comments - this has the added benefit of being able to generate html/latex and other sorts of docs for your code.