c

sYSMALLOc: Assertion failed - any ideas how to debug effectively ?

Hello, My server daemon works fine on most machines however on one I am getting: malloc.c:3074: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct mall...

"Type and Size Specifier" - Terminology

Take the following snippet: 1 #include <stdio.h> 2 #include <stdlib.h> 3 int foo(char [6]); 4 5 int main(void) { 6 char* bar="hello"; 7 return foo(bar); 8 } 9 10 int foo(char f[6]) { 11 return EXIT_SUCCESS; 12 } 13 What is the right technical term for "char [6]" on line 3? I call it "type and...

Library to parse C/C++ source code

Which library should I use to parse C/C++ source code file? I need to parse source file, calculate how much useful strings inside, how much 'for' blocks, 'if' blocks, how much comments inside. I also may need to insert a comment or small piece of code after each 'for' block. Is there any libraries? May be any library included in Micros...

Looping threads accessing pthread mutex

Hey all im building this application in which i have a client represented by a thread, running in loop (until it receives the instruction to terminate) trying to access a critical section of data in the server. When the first client connects to the server, he owns the lock to that mutex. all the subsequent connections are put to a hold...

How to use C macro's (#define) to alter calls but not prototypes

In our application (older parts) we alter calls to malloc (and realloc) and free so our own implementations are called instead of the standard runtime ones, e.g. #define malloc(s) OurMalloc(s) #define free(p) OurFree(p) This works quite good (for newer C++ code we simply implement global new and delete operators, so the C++ solution...

Why can't I use sizeof() in a #if?

I have this: #if sizeof(int) #error Can't use sizeof in a #if #endif I get this compiler error: missing binary operator before token "(" Why can't I use the sizeof operator here? ...

printf and ++ operator

Possible Duplicates: printf(%d %d %d\n,++a, a++,a) output problem Parameter evaluation order before a function calling in C #include<stdio.h> main() { int a=10; printf("\n %d %d", a, a++); //11 10 a=10; printf("\n %d %d", a++, a); //10 11 a=10; printf("\n %d %d %d ", a, a++,++a); //12 11 12 } after ...

How does logical negation work in C?

I have been using ! (logical negation) in C and in other languages, I am curious does anyone know how to make your own ! function? or have a creative way of making one? ...

Using C++ to Merge .reg files

Hey, I am simply trying to merge a .reg file into my registry using a very basic c++ program. The code is as follows: #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <stdlib.h> #include <cstdlib> #include <stdio.h> #include <windows.h> using namespace std; int main() { string file = "regedit.e...

Ideas for making a function for counting number of zero's in a bit string in C?

Can I make a function int bitParity(int x) that returns 1 if x contains an odd number of 0's using only these operators? ! ~ & ^ | + << >> ...

loading images only works when executable is open

[Edit] Note: These projects are projects that I have copied and renamed. Not sure if that would have anything to do with it. I am using the directx sdk and just playing around with it. I was trying to blit a image on to the screen by loading a external file. For some reason it does not work when I build it and run in debug. But If I go ...

What does this macro define?

Hello, I read this piece of macro(C code) and was confused in decoding it to know what it defines. What does it define? #define sram (*((unsigned char (*)[1]) 0)) -AD ...

return pointer to data declared in function

Hi! I know this won'T work because the variable x gets destroyed when the function returns: int* myFunction() { int x = 4; return &x; } so how do I correctly return a pointer to something I create within the function, and what do I have to take care with? How do I avoid memory leaks? I've also used malloc: int* myFunction2() { ...

How to compile with --pedantic-errors on OS X?

Here's a simple C file: #include <stdio.h> #include <stdlib.h> int main() { printf("hi there!\n"); return 0; } Compiling with gcc -ansi -pedantic -pedantic-errors gives this: In file included from /usr/include/i386/_structs.h:38, from /usr/include/machine/_structs.h:31, from /usr/include/sys/_struct...

Is there any non-GPL-opensource C\C++ H264 encoding library?

Could someone please point me to an opensource H264 encoding library (written with C/C++) that is not licensed under GPL? It is for not commercial app creation of cource. I just do not want to open its sources. ...

Where can I legally declare a variable in C99?

When I was first introduced to C I was told to always declare my variables at the top of the function. Now that I have a strong grasp of the language I am focusing my efforts on coding style, particularly limiting the scope of my variables. I have read this SO question on the benefits to limiting the scope and I came across an interesti...

Good Form: Pointer vs. local variable vs. Array Index

Forgive me if this comes across as a trivial question - I'm usually a control systems guy (plc's and automation) but have found myself involved in some embedded micro-controller and PC projects lately. Let's say I have a function that accepts a pointer to an array of 'command bytes', typically 5 or 10 bytes in length, like so: char...

Arithmetical operations with void* pointers to numerical data.

Hi I am working on small parser and "equation solver" in C, part of this process is to do arithmetical operations on tokens. Each token contains void* pointer to numerical data, and enum, which defines type of data. This is example of the function, which creates new token by adding two others tokens. In order to do so, I need to che...

Size of C data types on different machines & sizeof(complex long double)

Hi there, does anybody know a website or a paper where the sizes of C data types were compared on different machines? I'm interested in values of some 'big' machines like a System z or the like. And: Is there an upper bound of bytes that the biggest native datatype on any machine can have and is it always of the type complex long double...

How to detect the passing of a string literal to a function in C?

I am trying to implement an eqivilent version of perl's chomp() function in C and I have come across a corner case where a string literal passed as the argument will cause a segmentation fault (rightfully so). Example chomp("some literal string\n"); Is there a defined way in C99 to detect wether or not my function was passed a string ...