c

Prepare public header for release

Hi! I'm interested in hearing what routines you have for cleaning up public header files you distribute to customers. Some things I'd like to hear your opinions on are: Comments not meant for external consumption. Generally I like keeping documentation close to the code and comments like this might not be a good idea to share: /** *...

How to buffer stdout in memory and write it from a dedicated thread

I have a C application with many worker threads. It is essential that these do not block so where the worker threads need to write to a file on disk, I have them write to a circular buffer in memory, and then have a dedicated thread for writing that buffer to disk. The worker threads do not block any more. The dedicated thread can saf...

Using C++ Library in Linux (eclipse)

Hello everyone! I wrote a library and want to test it. I wrote the following program, but I get an error message from eclipse. #include <stdlib.h> #include <stdio.h> #include <dlfcn.h> int main(int argc, char **argv) { void *handle; double (*desk)(char*); char *error; handle = dlopen ("/lib/CEDD_LIB.so.6", RTLD_LAZY);...

how can I programatically get the name of an application?

I'm developing an orthogonal. Reporting/Logging system for several applications and was wondering how I can get an applications name on Windows using C/C++? the obvious requirement is I can't get it as a commandline argument or have the application tell me directly so I need to query the OS. Thanks for any ideas! ...

break in a case with return.. and for default

My OCD makes me add "break" when writing case statements, even if they will not be executed. Consider the following code example: switch(option) { case 1: a = 1; b = 7; break; case 2: a = 2; b = 4; return (-1); break; default: a = -1; break; } My two ...

Emacs indentation of break after switch statement

Right now the standard emacs indentation works like the following: switch (cond) { case 0: { command; } break; } I want the break; to line up with case. Also, is there a list of the c-set-offset commands somewhere? ...

Functions inside functions in C

Hi. I'm making a code that is similar to this: #include <stdio.h> double some_function( double x, double y) { double inner_function(double x) { // some code return x*x; } double z; z = inner_function(x); return z+y; } int main(void) { printf("%f\n", some_function(2.0, 4.0)); return 0; } This compiles perf...

How to fetch the end address of my code

Hey, guys - I'm writing a real-time operation system from scratch for a course project. I want to know the end address of my code after I download it to the chip, because I am planning to use the free memory for stack space and I need make sure that I won't overwrite the existing code. I heard about __end variable provided by GCC is th...

How to manage special cases and heuristics

I often have code based on a specific well defined algorithm. This gets well commented and seems proper. For most data sets, the algorithm works great. But then the edge cases, the special cases, the heuristics get added to solve particular problems with particular sets of data. As number of special cases grow, the comments get more an...

C/C++ Reflection and JNI - A method for invoking native code which hasn't been written yet .. feel free to tell me I'm an idiot

Hi All, I am implementing a piece of Java software that will hopefully allow for C libraries as plugins. In order to call these future functions I need to somehow create a native function in Java from which I can call the code that doesn't exist yet. The method signature will be static but the method and class names may change. I am ...

what is a "private header" in c

Hi I've been learning c recently, and in one of my textbooks I found a reference to a file with the extension .r (dot r). Now, as you can imagine, googling "r" or "file extension r" is not productive, so I wonder if you could help me out! It appears in the following code block #include "new.r" static const struct Class _String = { ...

Unit testing patterns for microcontroller C code

Although there are plenty of unit test frameworks that support C, I'm a little stumped on how to write unit tests for micro controller code (PIC in my case, but I think the question is more general than that). Much of the code written for micro controllers revolves around Writing configuration and data values to registers, reading incom...

My C Program provides a callback function for a hook. How can I keep it alive, un-kludgily?

Currently, I'm spawning a message box with a OS-library function (Windows.h), which magically keeps my program alive and responding to calls to the callback function. What alternative approach could be used to silently let the program run forever? Trapping 'Ctrl-c' or SIGINT and subsequently calling RemoveHook() for a clean exit would ...

c free memory

Hello, I have written a problem to practice pointers and allocating memory. However, I am getting a stack dump when I free the memory. Am I freeing in the correct place. Is there anything else wrong with my program that could make it unsafe? many thanks for any advice, void display_names(char **names_to_display, char **output); int...

Stages of compilation for a C program

When I write int main() { int j; } The memory for 'j' is allotted at the time of compilation,but when during compilation ? What are the various stages of compilation when memory is allotted to a variable? What if j was global ? ...

C Prog.: Structure as argument of function!?

I am trying to to create structure "Date of birth", and function that will assign values to the structure, and i am wondering is that possible to do that somehow like this: (PS. I am constantly getting error "Argument list syntax error", for 2nd and 23th lines.) #include <stdio.h> void input (dob_st *); int main () { typedef struct...

Difference between 'global' and 'static global'

A global variable's scope is in all the files.. while a static global variable's scope is just the file where it is declared.. why so ? where are global or static global variables stored in memory ? ...

How to change a value in memory space of another process

Hi all, If you could help me with this dilemma I have. Now, I know C \ C++, I know asm, I know about dll injection, I know about virtual memory addressing, but I just can't figure out how software like CheatEngine, and others, manage to change a variable's value in another process. For those who don't know, 3rd party cheat engine tools ...

Convert really big number from binary to decimal and print it

I know how to convert binary to decimal. I know at least 2 methods: table and power ;-) I want to convert binary to decimal and print this decimal. Moreover, I'm not interested in this `decimal'; I want just to print it. But, as I wrote above, I know only 2 methods to convert binary to decimal and both of them required addition. So, I'...

Is it possible to call a C function from OCaml passing a huge array efficiently?

I'm considering the use of a combination between OCaml and C code in a new application. It seems that calling C code from Ocaml is simple: external name : type = C-function-name However, it seems also that in the other way around (calling OCaml from C) is more complicated: static void call_ocaml_void (const char * name) { ...