c

To remove #ifdef DEBUG parts for release or not?

Hello, When releasing source code for someone else to see, when coding style is not well defined (no pun intended) do you remove the #ifdef DEBUG parts? (that is the parts that are compiled only when DEBUG is defined) If I remove it, it makes the code looks better (or me look better - do I really want someone to know I've debugged, and...

C/C++ pattern to USE_HEAP or USE_STACK

Is there a way to define a macro (or something similar) that would allow objects to be allocated on the stack or on the heap, cleanly? eg. Current code: A a; a.someFunc(); The simplest suggestion might be the following, but as you can see below, it's not very clean to maintain 2 sets of code. #ifdef USE_STACK A a; a.someFunc();...

Iterating a read() from a socket

Is this the proper way to iterate over a read on a socket? I am having a hard time getting this to work properly. data.size is an unsigned int that is populated from the socket as well. It is correct. data.data is an unsigned char *. if ( data.size > 0 ) { data.data = (unsigned char*)malloc(data.size); memset(&data.data, 0, data...

'Multipurpose' linked list implementation in pure C

( if you get easily bored reading long posts, you can focus on the bold parts ) Hello all! This is not exactly a technical question, since I know C kind of enough to do the things I need to (I mean, in terms of not 'letting the language get in your way'), so this question is basically a 'what direction to take' question. Situation is: ...

C function seemingly not defined anywhere!

I'm looking at the vim source code, specifically the file normal.c, and I see this function nv_operator being used, but it's not defined anywhere (I grepped the entire src directory) It's only declared as: static void nv_operator __ARGS((cmdarg_T *cap)); I've looked up the definition of __ARGS but it's just ... nothing (pretty much) ...

C# GUI Frontend

Is is possible to make a GUI in C# but make the actually program in C or C++. Like say I want to make a chat application. I want the interface to be in C#. But I want to make all the actual code in C. Is this possible? I found http://www.google.com/search?hl=en&q=P%2FInvoke&btnG=Google+Search&aq=f&oq= does anyone have ...

How do I find the smallest item in an array?

I have an array, and need to find the index of the smallest item. a = [2, 2, 2, 3, 3, 4, 3] This should return 0. Please note that the content and ordering of the array must not be modified. I am looking for a solution in either C or Java. ...

K&R Chapter 1 - Exercise 22 solution, what do you think?

I'm learning C from the k&r as a first language, and I just wanted to ask, if you thought this exercise was being solved the right way, I'm aware that it's probably not as complete as you'd like, but I wanted views, so I'd know I'm learning C right. Thanks /* Exercise 1-22. Write a program to "fold" long input lines into two or * more...

Monitoring low level hooks [C]

Is there any kind of way to monitor the low level keyboard hooks in a Windows enviroment. Say if I am making a program trying to find keyloggers. ...

C/C++: Array size at run time w/o dynamic allocation is allowed?

I've been using C++ for a few years, and today I don't know if this is a mere brainfart or what, but how can this be perfectly legal: int main(int argc, char **argv) { size_t size; cin >> size; int array[size]; for(size_t i = 0; i < size; i++) { array[i] = i; cout << i << endl; } return 0; } ...

Code convert from C++ to C

Hello, I have a Code which is C++ (*.cpp - source, *.hpp - header files). In the overall code,there are many classes defined, their member functions, constructors, destructors for those classes, few template classes and lots of C++ stuff. Now i need to convert the source to plain C code. I have following questions - 1.) Is there an...

Strange code crash problem?

I have a MSVC 6.o workspace, which has all C code. The code is being run without any optimization switch i.e with option O0, and in debug mode. This code is obtained from some 3rd party. It executes desirable as it is. But when I add some printf statements in certain functions for debugging, and then execute the code, it crashes. I sus...

Compare two values that have an arbitrary number of bits in C

I have created a dynamic typing system in C in order to create a dictionary that can contain values of different bit widths. The structure of the dynamic object is: typedef struct { void* Pointer; unsigned char Size; } Dynamic; I need to compare two of these Dynamics that hold A2D readings and then compare the difference a...

Open Source C/C++ embedded web server

I am working on a project where I need to embed a web server into my C++ application. I am looking for an open-source library supporting SSL, written in C or C++ and with a licensing scheme that will allow me to link it into my existing closed source code. Any suggestions of specific products or where to look first? ...

What happens to a malloc'ed block if you don't use it?

Consider the following C code: int main(){ int* c; c = (int*)malloc(sizeof(int)); c = 0xdeadbeef; free(c); return 0; } This will segfault because you are trying to free c, which is not something that has been malloc'ed before. My question is what happens to the block i just malloc'ed? Obviously c is not...

C function to convert a raw image to png

Hi, Is there any c function that allow me to convert a raw image to a PNG file? Preferably, I don't need to pull in a big library for that. Thank you. ...

How can I scale down an array of raw rgb data on a 16 bit display

Hi, I have an array of raw rgb data on a 16 bit display with dimension of 320 * 480. The size of the array is 320*480*4 = 6144000. I would like to know how can I scale this down (80 * 120) without losing image quality? I found this link about scaling image in 2D array, but how can I apply that to my array of 16 bit display? It is not ...

Is there any cure for the preprocessor blues?

I know that I can kick the the preprocessor to spit out output with the -E option in my particular circumstance. For generated code this preprocessor output is murderous. For example I have a 4gl application and Informix converts this into C which in turn gets spit out to a horrible ugly mess. What I want is an editor that will allow ...

File Handling question on C programming...

Dear all,, I want to read line-by-line from a given input file,, process each line (i.e. its words) and then move on to other line... So i am using fscanf(fptr,"%s",words) to read the word and it should stop once it encounters end of line... but this is not possible in fscanf, i guess... so please tell me the way as to what to do... ...

Why is my implementation of wc off by one word? [solved]

[Solved] Writing parsing code is a trap. A line with 15 spaces will have 15 words. Blank lines will also count as a word. Back to flex and bison for me. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp = NULL; ...