c

What is a good metaphor for c memory management?

I'm trying to find a good metaphor to explain memory allocation, initialization and freeing in c to a non technical audience. I've heard pass-by-reference/value talked about quite well with postal service usage, but not so much for allocation/deallocation. So for I've thought about using the idea of renting a space might work, but I won...

Is it possible to skip over an abitrary amount of a loop during debug?? Visual Studio

I am trying to find an error in my code. The problem is the error occurs in a loop. But the loop iterates about 500 times. Instead of clicking through the loop. Is it possible to skip over a certain amount of the loop ?? ...

Looking for some help working with premultiplied alpha

I am trying to update a source image with the contents of multiple destination images. From what I can tell using premultiplied alpha is the way to go with this, but I think I am doing something wrong (function below). the image I am starting with is initialized with all ARGB values set to 0. When I run the function once the resulting ...

Explanation of the disassembly of the simplest program (x86)

The following code int _main() {return 0;} Compiled using the command: gcc -s -nostdlib -nostartfiles 01-simple.c -o01-simple.exe gcc version 4.4.1 (TDM-1 mingw32) OllyDbg produced this output: Can you explain what happens here? Analysis so far: // these two seems to be an idiom: PUSH EBP // places EBP on stack MOV EBP...

Why doesn't this work?

I'v tried to solve a memory leak in the GLU callback by creating a global variable but now it dos not draw anything: GLdouble *gluptr = NULL; void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut) { GLdouble *vertex; if(gluptr == NULL) ...

Returning structs in registers - ARM ABI in GCC

Hi, In the ARM ABI documentation I come across functions defined like: __value_in_regs struct bar foo(int a, int b) { ... } but GCC(4.3.3) doesn't allow it and all I could find are references to some RealView compiler. Is there any way of doing this from GCC? I have tried -freg-struct-return but it doesn't make a difference. As ...

Speed up math code in C# by writing a C dll?

I have a very large nested for loop in which some multiplications and additions are performed on floating point numbers. for (int i = 0; i < length1; i++) { double aa = 0; for(int h = 0; h < 10; h++) { aa += omega[i][outsideGeneratedAddress[h]]; } double alphaOld = alpha; alpha = Math.Sqrt(alpha * alpha ...

How do bezier handles work?

On Wikipedia I found information about bezier curves and made a function to generate the inbetween points for a bezier polygon. I noticed that Expression Design uses bezier handles. This allows a circle to be made with 4 points each with a bezier handle. I'm just not sure mathematically how this works in relation with the formula for b...

Can C/C++ compiler report struct member offset

Possible Duplicate: Layout of compiled objects Hello, everyone. I'd like to ask, can compiler(e.g. Visual C++) generate a report(.txt) telling struct member offset for a struct/all structs? If so, it helps debugging quite a lot. For example, when you read disassembler code in the debugger, it can be easier to associate an off...

pass fortran 77 function to C/C++

hello. Is it possible to pass fortran 77 function as a callback function pointer to C/C++? if so, how? information I found on the web relates to fortran 90 and above, but my legacy code base is in 77. many thanks ...

Update multiple progress bar with gtk c++

I need to output the i progress bars and update them all. But only the last one updates i times. This is the code: static void calculaPi (GtkButton * boton, Datos * dDatos){ const char * threads; GtkWidget * barra, *bot2, *button, *progress, *vbox; threads = gtk_entry_get_text(GTK_ENTRY(dDatos->dthreads )); gint ithread...

post and pre increment in c

Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc) void main() { int a=2 , c; c=a++ + ++a + ++a + ++a; printf("%d",c); } prints 20, whereas void main() { int a=2; int c=a++ + ++a + ++a + ++a; printf("%d",c); } prints 17. Can some...

callin' c from lua crashs while reallocating

hi folks, i got a crazy error within that for-loop matr=realloc(matr, newmax*sizeof(matr*)); for (i=0; i<newmax; i++){ matr[i]=realloc(matr[i], newmax*sizeof(int)); } matr is a multi-dimension array: int **matr. i need to resize column and row. first line resizes column and the for-loop resizes every row. it worked fine in c. n...

Strange things appear on running the program

Hey! I'm fixing a program but I'm facing a problem and I cant really realize what's the wrong on the code. I would appreciate any help. I didnt post all the code...but i think with this part you can get an idea of it. With the following function enter() I wanna add user commands' datas to a list. eg. user give the command: "en james b...

Resizing a drawing area in GTK

My application performs a 90 degree rotation on a drawing area, so the width and height of the drawing area need to be swapped. How can I resize the drawing area with GTK in a way so that the new width and height are actually enforced, not just requested? ...

C/C++/Assembly Programatically detect if hyper-threading is active on Windows, Mac and Linux

I can already correctly detect the number of logical processors correctly on all three of these platforms. To be able to detect the number of physical processors/cores correctly I'll have to detect if hyperthreading is supported AND active (or enabled if you prefer) and if so divide the number of logical processors by 2 to determine the...

refactoring my code. My headers (Header Guard Issues)

I had a post similar to this awhile ago based on a error I was getting. I was able to fix it but since then I been having trouble doing things because headers keep blocking other headers from using code. Honestly, these headers are confusing me and if anyone has any resources that will address these types of issues, that will be helpful....

Is C a middle-level language?

In programming language discussions we hear terms such as low-level, middle-level, and high-level. How are these determined? Would C be considered a middle-level language? ...

Compatible types and structures in C

I have the following code: int main(void) { struct { int x; } a, b; struct { int x; } c; struct { int x; } *p; b = a; /* OK */ c = a; /* Doesn't work */ p = &a; /* Doesn't work */ return 0; } which fails to compile under GCC (3.4.6), with the following error: test.c:8: error: incompatible types in a...

Parser problem - Else-If and a Function Declaration

A quick, fun question - What is the difference between a function declaration in C/C++ and an else-if statement block from a purely parsing standpoint? void function_name(arguments) { [statement-block] } else if(arguments) { [statement-block] } Looking for the best solution! =) Edit: Thanks for the insight guys. I was actually ...