c

Proper handling of GetLastError (and others) in a multithreaded context.

Is it correct to assume that GetLastError (and variants) are per-thread or is it per-process? The problems if it is per-process are somewhat obvious in multithreaded apps because there is no way to guarentee that no other Win32 calls were made between your failed call and GetLastError. Sometimes the value of GetLastError is important. ...

c: program execution problem

Hi I wrote this code and compiled it, #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <time.h> // Data Structures typedef struct process{ char jobName; int arrivalTime; int execTime; struct process *next; } P; typedef struct result{ char Name; struct result *next; } result; // E...

Getting hardware information using java/jna to work on all operating systems

Hi I am trying to write a java applet that will get some hard ware info, mac address(which I have done), cpuid motherboard serial number and hard drive serial number. I know I need to use jna to do this. My question is, is there a way in c/c++ to get that information that is not platform dependent? Everything i have seen would work only ...

C Programming - Return Pointer to Freed

I have a function, foo(), that allocates memory and returns it. Is it standard practice for me to free it at the end of my main function? char* foo(){ char * p; p = malloc(sizeof(char) * 4); /* edit - thanks to msg board */ p[0] = 'a'; p[1] = 'b'; p[2] = 'c'; p[3] = '/0'; /* edit: thanks to the msg board. */ return p; } int ma...

What is the scope of the counter variable in a for loop?

I get the following error in Visual Studio 2008: Error 1 A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else This is my code: for (int i = 0; i < 3; i++) { string str = ""; } int i = 0; // scope error strin...

can a process create extra shell-redirectable file descriptors?

Can a process 'foo' write to file descriptor 3, for example, in such a way that inside a bash shell one can do foo 1>f1 2>f2 3>f3 and if so how would you write it (in C)? ...

Difference between Array initializations

Please see the following statements: char a[5]="jgkl"; // let's call this Statement A char *b="jhdfjnfnsfnnkjdf"; // let's call this Statement B , and yes i know this is not an Array char c[5]={'j','g','k','l','\0'}; // let's call this Statement C Now, is there any difference between Statements A and C? I mean both should be on Stack ...

gcc compile error: cast specifies array type

The following code is perfect valid, int *ia = (int[]){1,3,5,7}; but when I compile the next line of code, char *p = (char[]) "abc"; gcc says test.c:87: error: cast specifies array type It seems they are casted in the same way. Why did the second one get an err msg? As you guys said, "abc" is a pointer, which cannot be conver...

pcap_dump file not opened y Wireshark

I am trying to save the output of this file in libpcap format and although the file does get saved and the right data is written into it, Wireshark is unable to open it. Anyone see what I am missing here ? Thanks. // opening the device here to listen handle = pcap_open_live( dev, BUFSIZ, 1, 1000, errbuf ); unsigned int dlt = DL...

va-args not resolving correctly

I have the following function: void Register(Data* _pData, uint32 _Line, const char* _pFile, ...) { va_list Args; va_start(Args, _pFile); for(uint i = 0;i m_NumFloats; ++i) { _pData->m_Floats[i] = va_arg(Args, fp32); } va_end(Args); } Which is called by the macro: #define REG(_Name, ...)\ {\ if(s_##_Name##_...

How to call objective-C function from a C function

I'm trying to call an objective-C function from a C function but the code keeps crashing in objc_msgSend. My objective-C class is a singleton and I'm using the following code. void c_function(int arg0, const char *arg1) { [[objc_class instance] testFunction:arg0 Arg1:arg1]; } The gdb shows the crash is happening when object...

#line - purposes of?

I unfortunately was doing a little code archeology today (while refactoring out some old dangerous code) and found a little fossil like this: # line 7 "foo.y" I was completely flabbergasted to find such an archaic treasure in there. I read up on it on a website for C programming. However it didn't explain WHY anyone would want to use...

Using malloc() for unique pointers

So, I have some function returning a pointer, or NULL on error. Now I'd like to add another possible value for a different error/condition. I heard this mentioned in some other answer before - using malloc() to create a unique pointer that will serve as a possible value for such functions to return (so now the can return a proper pointer...

What's the easiest way to acquire a lock on a shared variable for a UNIX C program?

I am writing a C UNIX program that is threaded and shares one variable across all threads. What would be the easiest way to acquire a lock on this variable? I can't find any small libraries just for locking in UNIX. Any suggestions how to do this? Thanks, Boda Cydo. ...

iPhone to Flash porting

I need to port an existing game written for the iPhone to Flash. The iPhone game is mainly written in pure C rather than Objective C. I'm wondering if there are any good tools for converting the C code to Actionscript directly, or in general if anyone has some advice on how to do this porting in an efficient way given its C based source...

To generate hexadecimal numbers for 1000 bytes in C

Hi I want to generate hexadecimal numbers in C starting with seed value(initial value) 0706050403020100.My next numbers should be 0f0e0d0c0b0a0908 and so on for next iteration. In that way i want to generate numbers for say 1000 bytes. 1)how can i generate these hexadecimal numbers. 2)How to store these numbers if i want to...

String initializer and read only section

Suppose that I have an array(local to a function) and a pointer char a[]="aesdf" and char *b="asdf" My question is whether in the former case the string literal "aesdf" is stored in read only section and then copied on to the local array or is it similar to char a[]={'a','e','s','d','f','\0'}; ? I think that in this case the characte...

Finding security problems in a given code

Hello guys, Can some one please tell me an approach for finding security flaws in a given code. For ex: in a given socket program. Any good examples or good book recommendations are welcome. Thanks & Regards, Mousey ...

Store user-input in a variable

I was wondering how I could prompt the end-user of my program to type in a value they want to be converted from Fahrenheit into Celsius in C. Basically, since I'm a total n00b and I'm writing amazing "programs" such as this one: //Simple program to convert Fahrenheit to Celsius int main (int argc, char *argv[]) { doub...

casting void pointers

Possible Duplicates: Do I cast the result of malloc? Should I explicitly cast malloc()'s return value? Hello, gcc 4.4.4 c89 Normally I don't cast the return result from a malloc call. int *int_ptr = NULL; int_ptr = malloc(sizeof(int)); However, I have read on here, that if you cast it can hide errors. How does it hide ...