c

Distribute binary library on OSX

I'm planning to release some compiled code that shall be linked by client applications on MacOSX. The distribution is some kind of code library and a set of header files defining the public interface for the library.The code is internally C++ but its public interface (i.e what's being shown in the headers) is completely C. These are my...

Is it possible to stack Yacc grammar rule code?

Lets say I need to run some initialization code everytime I match a rule how can I reduce the redundancy? rule : TOKEN1 { init(); token1Code(); } | TOKEN2 { init(); token2Code(); } ; Also is it possible to do something like rule : TOKEN1 | TOKEN2 { codeForToken1OrToken2(); } ; ...

C Programming: Preprocessor, macros as tokens

Hi, I'm trying to do something that is conceptually similar to this, but can't seem to get it to work (error shown at end) any ideas? #include <stdio.h> int main( int argc , char const *argv[] ) { int abc_def_ghi = 42; #define SUFFIX ghi #define VAR(prefix) prefix##_def_##SUFFIX printf( "%d\n" , VAR(abc) ); return 0; } // un...

How to use a dll?

I have a .dll file and the .lib file for it. The DLL talks to an electronic key reader, and allows you to read/write the key ID. This is the only documentation that comes with: DLL Usage: boolean = object.DevicePresent (PROPERTY: true if the device is present) boolean = object.KeyPresent (PROPERTY: true if a key is in the device) long...

Reorder files and folders

Hi, I got a list of files and folders using dirent & stat in C, but they are not in the order I want. I want it will list the directories first then files. Ex: . .. [dir1] [dir2] [file1] [file2] Is there a way to do this with dirent? Or I dont want to manually order the output list. Thanks. ...

Installing new libraries on an OS X machine via terminal

I'm looking at using the tre tool provided at http://laurikari.net/tre/. I'm trying to install it on my Mac OS X box via the terminal. I've followed what I believe to be the regular path to install a new library - ./configure, sudo make, sudo install. Everything seems to go swimmingly. When I then go to access the library in c, I rec...

C Programming: Preprocessor, include files from macro

If I could find a way to do something similar to this, I could cut out hundreds of lines of code in my application, and dramatically increase maintainability. Anyone have any ideas? #include <stdio.h> int main( ) { #define include_all_files(root) \ #include #root "1.h" \ #include #root "2.h" \ ...

How do I show what fields a struct has in gdb?

I came upon a struct called ngx_http_variable_value_t in my gdb session and I would like to print what fields it has in the console. Is that possible? ...

Playing audio file using C

Hi, Are there are any header files to be included to play audio file using C language. ...

Can anyone suggest book for advanced C concepts?

Hi, I want to write programs like reading audio file and playing it. And I also wanted to write programs to convert one format (.vlc to ,rm). SO please suggest books and ebook links. ...

C OpenSSL block size

My code: EVP_DecryptInit (&ctx, EVP_des_cbc (), key, iv); if (EVP_DecryptUpdate (&ctx, outbuf, &olen, inbuff, in_length) != 1) { fprintf (stderr, "error in decrypt update\n"); return -1; } if (EVP_DecryptFinal (&ctx, outbuf + olen, &tlen) != 1) { fprintf (stderr, "error in decrypt final\n"); r...

Is there any regular expression engine which do Just-In-Time compiling?

My Questions is Is there any regular expression engine which do Just-In-Time compiling during regex pattern parsing and use when matching/replacing the texts? or where can I learn JIT for i386 or x64 architecture? Why I need that is, I recently trying to benchmark python's built-in regex engine with normal C codes with around 10M da...

Defining const pointer to a const string

Readed bog of Ulrich Drepper and come across 2 entries that looks like conficting. In the first one (string in global space) Ulrich states that the string should be defines as: const char _pcre_ucp_names[] = "blabla"; while already in second one (string in function) he argues it should be declared as: static const char _pcre_ucp_nam...

C - how to check whether all required fields of a structure are filled? (most elegant method)

I have a function, which has a pointer to some structure as its argument. How can I check within this function, whether all required fields of the structure have been filled before a function call? example: //lib.c void f(X_type *x) { ... } //user.c main(){ X_type object; object.name = "I am X"; object.ID = 1; ... f(X_type &object);...

Defining pointer to static string

In here it's said that for global variable the following form: (1) const char *a = "..."; is less good than: (2) const char a[] = "..." Why? I always thought that (1) is better, since (2) actually replicate the string we assign it, while (1) only points to it. ...

Initialising arrays in C++

Everywhere I look there are people who argue vociferously that uninitialised variables are bad and I certainly agree and understand why - however; my question is, are there occasions when you would not want to do this? For example, take the code: char arrBuffer[1024] = { '\0' }; Does NULLing the entire array create a performance impa...

How do you run several pthreads, in C, and detect the first to terminate?

How do you run several pthreads, in C, and detect the first to terminate? I'm thinking there has got to be an interface similar to select() for sockets to do this with threads. Thanks, Chenz ...

Making a perfect hash (all consecutive buckets full), gperf or alternatives?

Let's say I want to build a perfect hash table for looking up an array where the predefined keys are 12 Months, thus I would want hash("January")==0 hash("December")==11 I run my Month names through gperf and got a nice hash function, but it appears to give out 16 buckets(or rather the range is 16)! #define MIN_HASH_VALUE 3 #define M...

Grabbing memory from another process

in Windows, lets say I have used DLL Injection to get into another process. I have also done some screencaptures of the memory on the process I have injected into and know the location of the data I want to pull out. Lets say there is data in the other process at 0xaaaaaaaa that contains a certain value. How do I grab this value from tha...

Doing an INSERT from a C DB2 scalar UDF

Is it possible to do an INSERT statement inside a scalar C-language UDF in DB2? I know it sounds weird to have an UDF with side effects like this, but there's a good reason for it. ...