c

making sense of this parameter being passed

Hello, Linux gcc 4.4.1 I have this function that passes this second parameter that casts it to a different type. I am just wondering am I correct? It looks to me that it is casting the function evt_hdlr to a void * type to a long pointer type. if(enable_evt_hdlr(EV_ANY, (long (*) (void *)) evt_hdlr) == -1) { .. } The function evt_...

How to check if a file is already open by another process in C?

I see that standard C has no way of telling if a file is already opened in another process. So the answer should contain several examples for each platform. I need that check for Visual C++ / Windows though. ...

Macro and function with same name

I have the following code #define myfunc(a,b) myfunc(do_a(a), do_b(b)) void myfunc(int a, int b) { do_blah(a,b); } int main() { int x = 6, y = 7; myfunc(x,y); return 0; } I want the pre-processor to expand function myfunc only at calling. Required code after pre-processing looks like this: void myfunc(int a, int b) {...

Compile C code into Visual C++ dll?

Is it possible to compile C code into a Visual C++ dll? I'm looking at using some C code with a .Net project and trying to determine whether this is even an option. Thanks, Becky ...

How to find execution time (if possible in nanoseconds) of the sections in a C code on linux with intel dual core?

I have a C code with some functions.I need to find out the execution time of each function, I have tried using gettimeofday and rdtsc,but i guess that because its multi core system the output time provided involves the switching time between the processors. I wanted it to be serialized. So if somebody can give me an idea that how should ...

How to call the function using function pointer?

Suppose I have these three functions: bool A(); bool B(); bool C(); How do I call one of these functions conditionally using a function pointer, and how do I declare the function pointer? ...

How can i get UTCTime in milisecond since January 1, 1970 in c language

Is there any way to get miliseconds and its fraction part from 1970 using time.h in c language?? ...

How can I create a static variable in a Python class via the C API?

I want to do the equivalent of class Foo(object): bar = 1 using Python's C API. In other words, I want to create a Python class which has a static variable, using C. How can I do this? ...

Learning C++ Or C

Hi everybody My question is: Is learning C++ without learning C enough to program any kind of computer programs and get the computer to it`s maximum level (Full Control except the tasks that need Assembly language)? Thank you ...

What is the best way to implement a GUI without a GUI designer?

Hello everyone, if someone doesn't want to use an IDE (just an editor, a compiler and a debugger) what is the best way to impelement a GUI by hand? I think about a WinAPI-Application in plain C or C++. ...

Running C++ CGI Script As Background Process?

Hi, I'm working on an audio encoder cgi script that utilises libmp3lame. I'm writing in a mixture of C/C++. I plan to have an entry-point cgi that can spawn multiple encoding processes that run in the background. I need the encoding processes to be asynchronous as encoding can take several hours but I need the entry-point cgi to retur...

How does GTK Statusbar work? What's wrong with my code?

Dear developers, I would like to have a statusbar, so I started by making a small program with just a statusbar, so I could see how it worked. Right now I would just like to be able to get some text in it, but it shows a random character instead. Can someone see what's wrong with my code? #include <gtk/gtk.h> int main (int argc, cha...

How to get full path from SHBrowseForFolder function?

I'm using SHBrowseForFolder and SHGetPathFromIDList functions to get the selected folder path by user. However this method does not return the drive path of the full path. How to additionally get that information too? ...

"#include <asm/io.h>" causes "error: asm/io.h: No such file or directory"

I am using gentoo and trying to compile a program to control the bits on the parallel port. It has this line near the top of it: #include <asm/io.h> And when I try to use gcc on it, it produces this output: port.c:4:20: error: asm/io.h: No such file or directory "locate asm/io.h" yeilds (among other things): /usr/src/linux-2...

Dealing with similar code in multiple C "projects"

I am playing around with some C code, writing a small webserver. The purpose of what I am doing is to write the server using different networking techniques so that I can learn more about them (multithread vs multiprocess vs select vs poll). Much of the code stays the same, but I would like the networking code to be able to be "swapped o...

fclose return value check

Hi All, Is it required to check the return value of fclose? If we have successfully opened a file, what are the chances that it may fail to close? Thanks! Regards, Jay ...

How was Google.com made?

I'm very curious as to what programming languages were used to make Google. In the early days, Larry Page and Sergey Brin tried to licence their search algorithm to Yahoo. What I would love to know is what language(s) was the software first written in? I have a feeling it was C or perl (CGI), anyone know for sure? Thank you in advance ...

Python instance method in C

Consider the following Python (3.x) code: class Foo(object): def bar(self): pass foo = Foo() How to write the same functionality in C? I mean, how do I create an object with a method in C? And then create an instance from it? Edit: Oh, sorry! I meant the same functionality via Python C API. How to create a Python method ...

ANSI C - append chars to get a string

I have the following code in C: char *str = "Hello World"; char *s = malloc(strlen(str)); int i =0; for(;i<strlen(str)-5;i++) { s += *(str+i); } printf(s); It shows nothing. What I want is to get the substring of str stored in s. In Java I would do the following: String str = "Hello World"; ...

Passing a pointer from C to assembly.

I want to use "_test_and_set lock" assembly language implementation with atomic swap assembly instruction in my C/C++ program. class LockImpl { public: static void lockResource(DWORD resourceLock ) { __asm { InUseLoop: mov eax, 0;0=In Use xchg eax, resourceLock cmp ea...