c

Resources for programming a system that supports plugins

I need resources -preferably a text- about programming systems that supports plugins or extensibility and other related detailed stuff, like handling permissions and resources for those plugins ...

How to write bitmaps as frames to H.264 with x264 in C\C++?

How to write bitmaps (RGB) as frames to H.264 with x264 in C\C++? Some Examples with source would be great! ...

How to write bitmaps as frames to Ogg Theora in C\C++?

How to write bitmaps as frames to Ogg Theora in C\C++? Some Examples with source would be grate!) ...

can realloc move pointer if new size smaller?

I am wondering whether the C or C++ standard guarantees that a pointer is not changed when realloc is called with a smaller (nonzero) size: size_t n=1000; T*ptr=(T*)malloc(n*sizeof(T)); //<--do something useful (that won't touch/reallocate ptr of course) size_t n2=100;//or any value in [1,n-1] T*ptr2=(T*)realloc(ptr,n2*sizeof(T)); //<--...

C++ new operator. Creating a new instance

I'm having some trouble creating an object in C++. I create a class called Instruction, and I am trying to create a new instance, but I get compiler errors. Class code: class Instruction{ protected: string name; int value; public: Instruction(string _name, int _value); ~Instruction(); void setName(string _name...

Starting with an empty tree, what is the complexity of inserting into Red Black Tree in big-O notation?

If I have 10 elements and starting with an empty tree, What is the complexity of inserting 10 elements into Red Black in big-O notation? Is it going to be more than O(log 10) because each time it inserts an element, it has to search for appropriate location for the element and performs a series of rotations between ancestor nodes and c...

C Prototype scope

I learnt that the type specifier that declares the identifier in the list of parameter declarations in a function prototype (not part of a function definition), the identifier has function prototype scope, which terminates at the end of the function declarator. Please see the C program mentioned below. void fn (struct...

"error: too few arguments to function"

I have a C program called opencv2.0 function : cvSaveImage( out_img_name, img); Compiler gcc reports that too few arguments to function cvSaveImage The prototype of cvSaveImage in highgui.h is CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) ) After I change my call to be ...

macros as arguments to preprocessor directives

Being faced with the question wether its possible to choose #includes in the preprocessor i immediately thought not possible. .. Only to later find out that it is indeed possible and you only need to watch out for argument expansions (which e.g. Boost.Preprocessor can take care of). While i'd avoid actually doing that for includes if po...

void pointers: difference between C and C++

I'm trying to understand the differences between C and C++ with regards to void pointers. the following compiles in C but not C++ (all compilations done with gcc/g++ -ansi -pedantic -Wall): int* p = malloc(sizeof(int)); Because malloc returns void*, which C++ doesn't allow to assign to int* while C does. However, here: void foo(void...

What tool can catch buffer overflows in C?

So I have this simple piece of code which demonstrates a simple buffer overflow: #include <stdio.h> int main(void) { char c[4] = { 'A', 'B', 'C', 'D' }; char d[4] = { 'W', 'X', 'Y', 'Z' }; printf("c[0] is '%c'\n", c[0]); d[4] = 'Z'; /* Overflow that overwrites c[0] */ printf("c[0] is '%c'\n", c[0]); return 0...

example of thread specific data in C

Does anybody know of (or can post) an example of the use of thread-specific data? I'm looking for something that's clearly explained and easy to understand. I've got a global char * variable that I'm wanting to share between a couple threads, and I'm thinking this is what the thread specific data mechanism in C is for, am I right? I'm a...

fclose()/pclose() may block on some file pointers

Calling fclose() here after dup()ing its file descriptor blocks until the child process has ended (presumably because the stream has ended). FILE *f = popen("./output", "r"); int d = dup(fileno(f)); fclose(f); However by manually performing the pipe(), fork(), execvp() of the popen(), and then dup()ing the pipe's read file descriptor,...

Dynamic nested loops level

I'm trying to figure out a simple way to handle dynamic nested loops level. Consider the following function that takes in 2 parameters: #num of loops, and max value. void PrintLoop(int maxloop, int maxvalue) PrintLoop(1,2); // output 0 1 PrintLoop(2,2); // output 0, 0 0, 1 1, 0 1, 1 PrintLoop(3,2); // output 0, 0, 0 0, 0, 1 0, 1, 0...

How to write a http1.0 proxy server in c in linux?

I must develop proxy server that work with only HTTP 1.0 in Linux and by c . I need some hint to start developing . ...

The best compressor

What is the best memory and file compressor lzo, bzip2, zlib or lzma ? ...

File projection into memory using mmap

Hi, I'm trying to project a file into memory to operate with it. The file contais structs so I'm trying to use a pointer to the start of one struct and then read it and modify some variable. The problem is that the time of execution is high and I suppose that using mmap the time will be less. This is the code, any suggestion? #include ...

C comma operator

Why is the expression specified inside a comma operator (such as the example below) not considered a constant expression? For example, int a = (10,20) ; when given in global scope yields an error "initializer is not a constant", though both the expressions separated by a comma operator are constants (constant expressions). Why is th...

Sending an int over TCP (C-programming)

Hi! I have a server and a client program (both running on the same machine). The client is able to send a struct to the server with members such as "ID", "size" etc. Then I would like the server to send the ID-member (just an integer) back to the client as an ACK for validation, but I just can't figure this out despite being able to sen...

C structs don't define types?

I've just started learning C with a professional Java background and some (if no too much) C++ knowledge, and I was astonished that this doesn't work in C: struct Point { int x; int y; }; Point p; p.x = 0; p.y = 0; It seems that I have to declare p using struct Point as the type or using a typedef. Does this code works in C9...