c

extern C can not be used at class level?

Hello everyone, Just want to confirm in Windows environment, VSTS 2008 + C++ project, we could only apply extern C to function level, not be able to apply to class level (so that all member functions from the class use C language name mangling)? I have tried several ways, but always compile error. thanks in advance, George ...

Obfuscating C/C++ Code

Hi there What tools are available to obfuscate C/C++ code. I would prefer an open source solution. Thanks Update: Regarding the "use the compiler" responses I am aware of that but I have a client that wants to obfuscate their C/C++ code none the less I personally don't understand why, I have just been made responsible to implement a s...

When to use a void pointer?

I understand the use of void pointer for malloc implementation. void* malloc ( size_t size ); Can anyone suggest other reasons or provide some scenarios where it is useful in practice. Thanks ...

Setting variable to NULL after free ...

In my company there is a coding rule that says, after freeing any memory, reset the variable to NULL. For example ... void some_func () { int *nPtr; nPtr = malloc (100); free (nPtr); nPtr = NULL; return; } I feel that, in cases like the code shown above, setting to NULL does not have any meaning. Or am I missin...

doubts in double pointer in C

the follwing code is run successfully ... typedef struct _s { int *r; }s; void main() { s *u; int y=1000; u=malloc(sizeof(s)*8); u->r=malloc(sizeof(int)*8); u->r[5]=y; printf("%d\n",u->r[5]); getch(); } but i write the follwing code as above but gives error ....i use structure.....may why i know the reaso...

Modifying a C string: access violation

Possible Duplicates: Why does simple C code receive segmentation fault? Modifying C string constants? Why does this code generate an access violation? int main() { char* myString = "5"; *myString = 'e'; // Crash return 0; } ...

Import a variable into a C program from a Makefile

Hi all, I am required to make some changes in an existing long C source code. There is a top-level Makefile which defines the various compiler options like directory locations of libraries used by the linker. Something like : LD_OPTIONS = $(PATH_TO_MYLIB1) $(PATH_TO_MYLIB2) Now, I am thinking of using dlsym() and dlopen() to use the...

What common algorithms are used for C's rand()?

I understand that the C specification does not give any specification about the specific implementation of rand(). What different algorithms are commonly used on different major platforms? How do they differ? ...

Can I write a C application without using the heap?

I'm experiencing what appears to be a stack/heap collision in an embedded environment (see this question for some background). I'd like to try rewriting the code so that it doesn't allocate memory on the heap. Can I write an application without using the heap in C? For example, how would I use the stack only if I have a need for dynami...

Good Gui editors for win C programming

Hey! I am trying to get back to C programming in windows. I normally use codeblocks for the code and for the gui I used Resource Editor from radasm, but it seems it's no longer available. Anyone know of a simple program that will let me create dialogs, edit existing resource files and such easily? Thanks ...

What happens when we dont specify datatype of arguments in a function and pass parameters to it while calling it?

Look at the following program. int main() { char a=65, ch ='c'; printit(a,ch); } printit(a,ch) { printf("a=%d ch=%c",a,ch); } Even if the data type of the arguments is not specified in the function 'printit()', the result is shown on printf. I see correct answer when i compile it with gcc and run it.Why? Is it not neces...

How to use SpiderMonkey on Windows

Hi, I would like to use SpiderMonkey ( the javascript engine from Mozilla ) in my application. I want to use the js3250.dll shipped with firefox but i have a pb from the very beginning. It seems that the JS_NewRuntime method is not available anymore (according to the depends tool ). Any idea how to embed the javascript engine into anoth...

Performing an operation at an interval

I want to perform the action at a certain timeout, like fire an event. I figured out how to do every n number of seconds, but not 1.5 seconds. Here is what I have. Please suggest how to handle my case: void Publish() { static int local_time=time(NULL); int current_time = time (NULL); if((current_time+PUBLISH_TIMEOUT)>loc...

Comparing strings in C - strcmp

I'm having trouble comparing strings in C (with which I am fairly new to). I have socket on this server application waiting to accept data from a client. In this particular portion of my program I want to be able to execute a MySQL query based on the data received from the client. I want to be able to know when the received data has the ...

Why Switch/Case and not If/Else If?

This question in mainly pointed at C/C++, but I guess other languages are relevant as well. I can't understand why is switch/case still being used instead of if/else if. It seems to me much like using goto's, and results in the same sort of messy code, while the same results could be acheived with if/else if's in a much more organized m...

Obj-C: C functions declared inside or outside @implementation block, what's the difference?

what's the difference between a C function (static or not) declared inside or outside the implementation block (@implementation ... @end) of a Objective-C class? is this specially true?: If you need to poke inside of the object directly, you can put this function inside of the @implementation block of your class, and then you can ac...

MD4 implementation in C -- consistent, yet erroneous output

I can't seem to get my md4 implementation working. Any ideas as to what's wrong? Also, I'm not in the class that this project was assigned to.. I'm just doing it for kicks. I would also rather you give me hints than an outright answer. Thanks! EDIT: To be specific (as I know to be), my outputs do not match the test vectors provided ...

What is the BSD (or portable) way to get ToS byte (like IP_RECVTOS from linux)?

What is the right (portable, stable) way to get the ToS byte of a received packet? I'm doing UDP with recvmsg() and on linux I can get the ToS if I setsockopt() IP_RECVTOS/IPV6_RECVTCLASS, but IP_RECVTOS doesn't seem to be available on my BSD systems. What is the right way to do this? I primarily want this to work on the BSDs and Solari...

GCC on HP-UX, lots of poll(), pipe(), and file issues

I'm having a lot of trouble building a 'middleman' logger - the intention is to place it on the path above an item in /usr/bin and capture everything going to and from the application. (Black box 3rd-party app is failing FTP for some reason.) Once run, the middleman will fork, redirect stdout and stdin to/from pipes that the parent has...

What happens when an inline function is passed as a parameter in C?

Today I was writing some C code to sort an array of structs using quicksort with a custom comparator function to determine their ordering. At first I wrote it with the call to the comparator function hard-coded into the quicksort function. Then I thought perhaps it would be nicer to pass that function as an argument to a generic quickso...