c

Pthreads problem and a few questions...

#include<pthread.h> #include<stdio.h> #include<stdlib.h> #include<time.h> #define NUM_THREADS 8 char *messages[NUM_THREADS]; struct thread_data { int thread_id; int sum; char *message; }; struct thread_data thread_data_array[NUM_THREADS]; void *PrintHello(void *threadarg) { int taskid, sum; char *hello_msg; struct ...

why a[n] is accepted in c during runtime?

why can we do this in c? int n; scanf("%d",&n); int a[n]; I thought array is located memory during load time but seems like the above example works during runtime. Do I misunderstand any thing? can you guys help? Thanks, ...

Why hasn't a faster, "better" language than C come out?

With all the new "modern" languages out today, how is it that C is still heralded as the fastest and "closest to the machine"? I don't really believe in there ever being only one correct way to do things, and C has been around for a really long time (since the 60's!). Have we really not come up with anything better than something written...

Byte precision pointer arithmetic in C when sizeof(char) != 1

How can one portably perform pointer arithmetic with single byte precision? Keep in mind that: char is not 1 byte on all platforms sizeof(void) == 1 is only available as an extension in GCC While some platforms may have pointer deref pointer alignment restrictions, arithmetic may still require a finer granularity than the size of the ...

is it necessary to learn java for contributing to an open source project?

I am more into c/c++. But many of my seniors here in college ask me to learn java if I want to contribute to an open source project.. I m in dilemma. what to do?? Can't we do a design project in c/c++?? ...

how to deal with error return in c

How does one deal with error return of a routine in C, when function calls go deep? Since C does not provide an exception throw mechanism, we have to check return values for each function. For example, the "a" routine may be called by "b", and "b" may called by many other routines, so if "a" returns an error, we then have to check it in...

Is there a cross platform version of window vista's slim reader writer locks?

I'm totally blown away from the quality of windows SRW implementation. Its faster then critical sections and its just a few bytes memory overhead. Unfortunately it is only Windows Vista/Windows 7. As this is a pure user land implementation, does anybody know if there is a cross platform implementation for it? Has anybody reverse-engi...

C Program on Linux to exhaust memory

I would like to write a program to consume all the memory available to understand the outcome. I've heard that linux starts killing the processes once it is unable to allocate the memory. Can anyone help me with such a program. I have written the following, but the memory doesn't seem to get exhausted: #include <stdlib.h> int main() ...

What should I use instread of g_strncasecmp?

It looks like g_strncasecmp is deprecated, so I am looking for another function to do the same thing. ...

Sorting 2D arrays in C/C++ in increasing values; knowing the original positon after sorting ?

I have already written a program that sorts a 2D array in increasing values. Here is my input and output. Input: Array2D[0][0] = 99 Array2D[0][1] = 10 Array2D[0][2] = 97 Array2D[0][3] = 10 Array2D[0][4] = 14 Array2D[1][0] = 73 Array2D[1][1] = 53 Array2D[1][2] = 81 Array2D[1][3] = 22 Array2D[1][4] = 88 Output: Array2D[0][0]...

Applications in C language!

I'm doing post graduation in Computer science. I want to do a project in 'C' in group of 2 people but I'm not able to find any topic for that. Please can anyone suggest me? and a brief description about the topic? I've well knowledge about pointers,strings,arrays,file handling! If the project requires new things to be learned then its po...

Preprocessor metaprogramming library for plain C

Hi, does anybody know a library similar to boost::preprocessor (maybe not so advanced) that could be easily used/incorporated in plain C projects? Of course, the most (all ?) of boost::preprocessor is usable when writing in C but I would prefer a small library with only basic capabilities that doesn't depend on the monster like boost. ...

How to find out ALSA audio device capabilities programmatically in Linux without opening the device

How do I find out the capabilities of ALSA devices without opening the device first? Problem is, I need to supply the parameters to the snd_pcm_open() function to use the test functions which to me is silly. Why ask whether this is a playback or record device if I have to tell it to the open function first? As an example, I would like ...

GCC performance

Hello, I am doing parallel programming with MPI on Beowulf cluster. We wrote parallel algorithm for simulated annealing. It works fine. We expect 15 time faster execution than with serial code. But we did some execution of serial C code on different architectures and operating systems just so we could have different data sets for perfor...

Replacing a function definition in C

Possible Duplicate: What is the best solution to replace a new memory allocator in an existing code? I'm writing a library in C. I'd like to know if there is a way to divert every malloc() call my library makes to a different "augmented" testmalloc() function that I provide without (significantly) modifying my library. This qu...

Sqlite API boolean access

This should be an easy question I figure, but I hadn't found this answered else where surprisingly, so I'm posting it here. I've inherited a Sqlite driven database which contains boolean columns in it, declared like this: CREATE TABLE example ( ex_col BOOLEAN NOT NULL DEFAULT 0, ); This table is trying to be accessed via the sqlite...

Changing from Web Development Career to C/C++

I have been doing web development for the past 3 years, mainly in PHP and MySQL. Lately I have been changing into the C/C++ area. The reason is that I want to try out something new and expand my skillset before deciding which area I want to focus on. I would like to get advice from you guys about this. Is this a good idea? Is it a bad i...

Casting a void pointer (data) to a function pointer

I know this has been asked before but none of the cases I've seen here are like this one. I am importing some API functions at runtime, the general declaration on those functions would be like: // Masks for UnmapViewOfFile and MapViewOfFile typedef BOOL (WINAPI *MyUnmapViewOfFile)(LPCVOID); typedef LPVOID (WINAPI *MyMapViewOfFile)(HAND...

Using custom Makefile with Eclipse/CDT.

I have a project of multiple .c and .h files and i write my own Makefile. How to configure Eclipse to use my Makefile and my source files from their original locations? ...

Reading tag data for Ogg/Flac files.

I'm working on a C library that reads tag information from music files. I've already got ID3v2 taken care of, but I can't figure out how Ogg files are structured. I opened a .ogg file in a hexeditor and I could find the tag data because that was all human readable. But everything from the beginning of the file to the tag data looked l...