This question already has answers here:
Underscore `_` before the format string
(3 answers)
Closed 3 years ago.
What's the role of the _("hello, world\n") argument to printf/puts etc ? I often find it while reading GNU source code.
See GNU Gettext -- it (_(...)) is used as a "binding site" for translation.
This is the gettext internationalization system.
it is a macro that replaces the gettext translation function. For a thorough explanation on gettext, check out this write-up: http://oriya.sarovar.org/docs/gettext_single.html
The underscore function (or macro) is a custom function defined by whatever project you're looking at. By convention, it's defined to send the string to GNU Gettext to fetch a translated version of the string for the user's current language.
This use of the _ macro is documented in the overview found in the GNU Gettext manual.
Related
This question already has answers here:
Regular expressions in C: examples?
(5 answers)
Closed 6 years ago.
I am novice to C programming. Is it possible to match pattern inside the C string, like any built in functions?
I am using Red Hat Linux and I want to check if a string starts with abc: or def: followed by 10 digit numbers # chars. Something like : (abc|def):([0-9]{10})#([A-Za-z0-9]*).
Is there any C built in function which I can use to check this pattern matching.
Thanks for your help.
You can use POSIX regex matching in linux. See man 3 regex for more details.
If you are looking for a fast, safe and threaded library you can use re2 library from Google with support like pre-compiled regex.
(https://github.com/google/re2)
Linux and POSIX have regex(3) functions. You'll need to "compile" -that is prepare by transforming- your regular expression string using regcomp first.
In some simple cases, you might also use other string functions, like strstr, strchr, sscanf(3) (the %n format specifier might be handy, to know how much bytes you have scanned).
You could also consider some lexing utility, perhaps using flex to generate a tokenizer able to recognize your regexp.
This question already has answers here:
How to embed version information into shared library and binary?
(4 answers)
Closed 6 years ago.
I have situation as below:
#define CONSTANT 123
foo()
{
...
}
Using the above code, after creating the library lets say test.so, how can get to know the CONSTANT macro value from the library? Is there any way?
You can define the constant in a header file and supply that header with the library.
There are ways to do that:
Define the constant in a header file to the library and distribute it with the library
Make the library some form of open source
Write a dedicated get_constant function that returns the value
Its worth noting that Macros are always sheer text replacement. So after compile time you won't even know they were there.
This question already has answers here:
Why does the C preprocessor interpret the word "linux" as the constant "1"?
(5 answers)
Closed 8 years ago.
With in a source code I know you can use platform specific information such as
#ifdef __APPLE__
or
#ifdef __ANDROID__
I am working on a new platform and need to use such macros. Where does the definition occur? If it is done at the compiler, where can i look to find this information?
It is said that the NaCl MACRO for instance is defined at the compiler as follows:
/* The NACL compiler defines __native_client__ and __pnacl__
* Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi
*/
EDIT:
I guess I'm Looking for predefined compiler macros like the ones mentioned in http://sourceforge.net/p/predef/wiki/Compilers/. But is there a way I can look into a given compiler to find these information to find additional information? The one I use is based on arm-gcc.
Some sources:
http://www.netbsd.org/docs/pkgsrc/fixes.html#fixes.build.cpp
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/predefined-macros-platform.html
Boost has a library Predef that define a lot of macro of a lot of platform too.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Where to find stdio.h functions implementations?
In C i have been using headers that contain prototypes and declarations of functions provided by the libraries, but where are functions like printf, scanf, etc. stored?
Where are they stored?
In which directory?
Why can't i find them? Are they stored as object files?
As everyone said, its int libc. You can search google for source code browser for the OS you are interested in, for linux I could find: http://lxr.linux.no/linux/
For netbsd, you can find printf and scanf here:
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/?only_with_tag=MAIN#dirlist
These functions are provided by the standard C library, often called libc.
In linux, you can find it under /lib/libc.so
In Windows they call it C Run-Time Libraries.
On Mac OS X, those functions are in stdio.h and is located in /usr/include. The library libc.dylib is in /usr/lib.
One place to check out is the section 3 of the manual. Then each individual function manual page lists the required header files and what additional libraries, if any, you need to link with.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Where to find stdio.h functions implementations ?
Hi, I am trying to find the function definitions of the functions defined in stdio.h header file, I want to learn how functions like printf() is achieved, but I can't find any preprocessor directives link in stdio.h to the implementation file elsewhere. How can a C Compiler know where to find the implementations when there are no direct references to the function definition file? (I learned that .h file may accompany with a same name .c implementation file from an objective-c book.) Could you help me? Thanks! I am using GCC on Mac OS X.
FreeBSD's libc is pretty well laid out in its src repository.
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/
e.g. for printf(3):
http://svnweb.freebsd.org/base/head/lib/libc/stdio/printf.c?view=markup
http://svnweb.freebsd.org/base/head/lib/libc/stdio/vfprintf.c?view=markup
Try downloading source code for GLIBC library project. That's where definitions for standard functions are when using GCC compiler (and derivates).