c

Can't build sigqueue example with gcc but g++ is ok?

Hi I have a strange build problem. I have a simple test program that sends a sigqueue to another process. This little code example builds and runs when I build it as a c++ program (compiled with g++) but when I compile it as a c program (with gcc) I get a error that he can't find the sigval struct. The short example: #include <std...

freeing memory issue

Hi All, I have an issue regarding freeing memory as under: string points; // some points sequences char* charPoints = (char*)malloc((points.length() +1) * sizeof(char)); //do something free(charPoints); Even then after freeing memory is leaked when checked with instruments ...

What is a difference between unsigned int and signed int in C?

Consider these definitions: int x=5; int y=-5; unsigned int z=5; How are they stored in memory? Can anybody explain the bit representation of these in memory? Can int x=5 and int y=-5 have same bit representation in memory? ...

C Array address confusion

Suppose I have the following code: main () { char string[20]; printf(" The String is %s \n " , &str); } What would printf(" The String is %s \n " ,&str); give? Suppose str points to location 200, what would &str give?? ...

Makefile Packages in C

What packages do i need to install in order to use a Makefile. I've already installed cmake, would i need ocamlmakefile? My problem is that whenever i type 'make' into the terminal, i'm told "make command not found". ...

using legacy project in Eclipse

Hi, I wish to use "C" legacy project in the Eclipse. In the project it require "autoreconf -vi" followed by "./configure" before make to start. My problem is I am not able to do "autoreconf -vi" and "./configure" from the eclipse. Thanks Arpit ...

What are the internal processes involved for a C compilation ?

hi, I have a set of *.C files(embedded related). Could anyone please detail to me the steps/processes(internal information) involved while compiling followed by linking to create the final executable(I need the information/steps regarding what a preprocessor/compiler generally performs to a C src code) Also i just want to get an idea ...

What do companies use to build their binaries?

What do modern companies use to compile and link their projects? Especially with large projects, makefiles don't seem usable enough to be scalable. As far as I can tell, many companies use either in-house build systems or in-house scripts on top of existing build systems. Do large projects use make? Is pure Ant, Maven, etc used or is...

Is it bad practice to use C features in C++?

For example printf instead of cout, scanf instead of cin, using #define macros, etc? ...

What's the logic behind this C code??

for(int i=0 ; i++ ; printf("%d",i)); printf("%d",i); O/P is 1 . If we take i=1 then there is an absurd output and if i=-1 then output is 01. How is the For loop functioning.Plz Help.Thanx. ...

General question about winsock's recv-function

Hi, I've got a general question about the recv-function of winsock. I write a programm with a client/server-architecture where the client sends a camera image to the server and the server sends another image back to the client. The client sends serveral images until the program is closed. And the server will responds every received imag...

Valgrind errors

I have recently developed a habit of running all of my programs through valgrind to check for memory leaks, but most of its results have been a bit cryptic for me. For my latest run, valgrind -v gave me: All heap blocks were freed -- no leaks are possible That means my program's covered for memory leaks, right? So what does this err...

array puzzle:generating all possible combinations

hello, im doing a project and this part is rly important to me.i'll try to be as clear as possible. suppose we have an mxn matrix with all 0s, i need to generate all possible combinations of the array in which only one element in a row is initialised to 1 and all the other elements in that row are 0s. similarly, in all the rows, exactly...

Declaring an array with a non-constant size variable

Hi I'm studying for my test in C and I'm reading in a C summary I downloaded from some site. It is written that it is not allowed to write arr[i] where i is a variable. The only way to do it is with malloc. However, I wrote the following code and it compiles without warnings and without error on valgrind: int index = 5; int a4[...

Implementing C's enum and union in python

I'm trying to figure out some C code so that I can port it into python. The code is for reading a proprietary binary data file format. It has been straightforward thus far -- it's mainly been structs and I have been using the struct library to ask for particular ctypes from the file. However, I just came up on this bit of code and I'm at...

C pointers - Different address

I'm trying to learn about C pointers but I cannot understand somethings... The following code: #include <stdio.h> void foo(int *x, int *y); void foo(int *x, int *y) { printf("x = %p\ny = %p\n", &x, &y); *x = 5; *y = 6; } int main(void) { int a, b; printf("a = %p\nb = %p\n", &a, &b); foo(&a, &b); return 0; ...

ALSA: Looping Sound Problem

I have written a small program that tests the ALSA library on an Embedded Linux board. The program configures ALSA, plays a single sound and then waits 1 minute before exiting. Here is what I am observing: after playing the sound, there is silent pause and then the sound is played again. I am 100% positive that the program itself is not...

How to implement Bitcount using only Bitwise operators?

The task is to implement a bit count logic using only bitwise operators. I got it working fine, but am wondering if someone can suggest a more elegant approach. Only Bitwise ops are allowed. No "if", "for" etc int x = 4; printf("%d\n", x & 0x1); printf("%d\n", (x >> 1) & 0x1); printf("%d\n", (x >> 2) & 0x1); printf("%d\n", (x >> 3) &...

Seg Fault when initializing array

Hi guys, I'm taking a class on C, and running into a segmentation fault. From what I understand, seg faults are supposed to occur when you're accessing memory that hasn't been allocated, or otherwise outside the bounds. 'Course all I'm trying to do is initialize an array (though rather large at that) Am I simply misunderstanding how to ...

C pointers - Point to the same address

#include <stdio.h> #include <stdlib.h> void foo(int *a, int *b); void foo(int *a, int *b) { *a = 5; *b = 6; a = b; } int main(void) { int a, b; foo(&a, &b); printf("%d, %d", a, b); return 0; } Why a = b (foo) doesn't work? printf outputs "5, 6" Thank you. ...