c

Flexible array members in C - bad?

I recently read that using flexible array members in C was poor software engineering practice. However, that statement was not backed by any argument. Is this an accepted fact? (Flexible array members are a C feature introduced in C99 whereby one can declare the last element to be an array of unspecified size. For example: ) struct hea...

Replacing typelibs for imports

I am working on a project which uses an import #import "progid:Blah.blah.retrieve" rename_namespace("Blah") but I would really perfer not to register the dll which is I believe what is missing to allow this to work. I don't want to register the dll because our build system will not be able to build multiple instances at a time. Is t...

How can I experiment with garbage collection?

I'm interested in how garbage collection works. I've read up on how some work such as mark-and-sweep, stop-and-copy, generational GC, etc... I'd like to experiment with implementing some of these and comparing their behaviors. What's a good way to get started experimenting with my own? Ideally something in C, Java or Python (although the...

How to solve this compatibility-problem regarding large file support?

A library using off_t as a parameter for one function (seek). Library and application are compiled differently, one with large file support switched off, the other with large file support. This situation results in strange runtime errors, because both interpret off_t differently. How can the library check at runtime the size of off_t for...

unions declaration C code

I have seen some declaration of a union inside a struct as follows. Example code given below. My questions is does it help in any memory savings(typical use for which a union is used for)? I do not see the benefit. typedef struct { int x1; unsigned int x2; ourstruct1 ov1; ourstruct1 ov2; union { str...

when would you use uint_least16_t

I'm looking at stdint.h and given that it has uint16_t and uint_fast16_t, what is the use for uint_least16_t what might you want that couldn't be done equally well with one of the other two? ...

Multiple definitions due to multiple includes of same header file

Hello, I have a header file x.h which is included by more than one *.c source files. This header file has some structure variables defined. I have put multiple inclusion prevention guard at the beginning of the header file as: #ifndef X_H #define X_H ... .. //header file declarations and definitons. #endif//X_H On building I get l...

Whether const char * and strdup serve the same function when used with getopt in C?

Hi, In the below code snippet can i replace char * to const char * and remove the strdup() function call and directly take the optarg value set by getopt()? I am advised to use const char * to skip the strdup function usage. Appreciate the help in advance. /* Code Snippet */ char *dir = NULL; char *bld = NULL; int chr; while ( ( chr ...

difference between pointers?

What is the difference between int *a[3] and int (*a)[3]? ...

Does anyone know of any C/C++/C# code libraries that do audio synthesizer emulation?

I'm trying to write a software synthesizer that recreates the sounds made by classic synthesizers like the Moog and the DX7. Does anyone know of any code resources for something like this? Thanks. ...

How difficult is it to turn a "Java School" programmer into a C or C++ programmer?

My company, a C++ house, is always looking to hire recent grads. However due to the Java Schools phenomenon, we typically end up interviewing strong Java programmers with maybe a minute smattering of C++. Often the C++ classes don't really prepare students for working in C++. Nevertheless, often these are bright kids, eager to learn and ...

Segment violation on attempt to initialize a memory mapped file

The following is code I've used to create a memory mapped file: fid = open(filename, O_CREAT | O_RDWR, 0660); if ( 0 > fid ) { throw error; } /* mapped offset pointer to data file */ offset_table_p = (ubyte_2 *) shmat(fid, 0, SHM_MAP); /* Initialize table */ memset(offset_table_p, 0x00, (table_siz...

Why was the switch statement designed to need a break?

Given a simple switch statement switch (int) { case 1 : { printf("1\n"); break; } case 2 : { printf("2\n"); } case 3 : { printf("3\n"); } } The absence of a break statement in case 2, implies that execution will continue inside the code for case 3. This is not an ...

Unions in C

When should unions be used? Why do we need them? ...

Functions in C

Can we call functions using function pointer? if yes how? ...

Why this union is deleting the 1st records in arrays in the c code?

look at one of my header file which consists of a union template with 4 different structures. <#define MAX 3 union family { struct name /*for taking the name and gender of original member*/ { unsigned char *namess; unsigned int gender; union family *ptr_ancestor; /*this is a pointer to his ancestors detai...

auto c/c++

Has anyone ever seen the storage class auto explicitly in use in c/c++? If so, in what situation? ...

how to use array of function pointers?

how to use array of function pointers in c? how to initialize them? ...

Why should we typedef a struct so often in C?

I have seen many programs consisting of structures like the one below typedef struct { int i; char k; } elem; elem user; I have seen this many times. Why is it needed so often? Any specific reason or applicable area? ...

strdup() - what does it do in C?

What is the purpose of the strdup() function in C? ...