-   Programming (
-   -   translating C software from Win to Linux (

altella 07-03-2007 03:48 AM

translating C software from Win to Linux

At work I need to translate some software writted in C code from Windows to Linux.
This software uses some functions of the windows API, and I donīt know how to translate them to Linux. These are my main problems:
- Timers support: At the moment I am using "SetTimer()" to stablish events after some time has passed. How could I do it with Linux?
- Thread support. I think this will not issue problems. It is well explained in "Advanced Linux programming" book.

I would be very grateful if you could help me with the timers problem.

Best regards,

nc3b 07-03-2007 06:02 AM

Hello. Here's what my drunken neuron has come up with a long time ago.

First declare a structure to gold parameters.

PHP Code:

struct param
int pass_int;
int interval;

Then declare an all-purpose function, which will call your functions.

PHP Code:

void * function(void_parameter)
param parameter=(param*)_parameter;

Declare some dumb class

PHP Code:

class timer
param parameter;
pthread_t thread_id;
timer(int _interval,int(*_function)(int),int _pass_int)

Two "user" functions
PHP Code:

int function_to_run(int a)

int function_to_run2(int a)

Cross your fingers..

PHP Code:

int main(int argcchar** argv)
timer *tm2=new timer(2,&function_to_run2,43);
timer *tm=new timer(1,&function_to_run,47);


Of course, I have done no error testing, and as you can see, I am really not using the int parameter to the functions, nor am I using the functions return values.. (ugh.. the values they should return :o ).

Anyways, I am sure there's lots and lots of timer classes on the net.

chrism01 07-04-2007 07:19 AM

Looks like C code to me ?

nc3b 07-04-2007 08:08 AM

What I wrote is not C code (look, there's that dumb class). I know the guy asked for C code, but I believe it's easy to quickly turn it into C code.

chrism01 07-04-2007 08:40 AM

True, what I meant was not the actual code content, but the 'PHP Code:' comment before each (C++) code block. It looks weird (possibly confusing to a newbie).

nc3b 07-04-2007 09:06 AM

You are right, it has happened before :) , but I php code has syntax highlighting.. In the future, I will avoid using php code tags or I will clearly state which language is the code written in. Cheers. :)

jtshaw 07-04-2007 02:12 PM

For time timer code I would investigate setitimer and getitimer.

nc3b 07-04-2007 04:42 PM

I agree jitshaw. I actually found an example here. This could prove useful for me too in the future.

All times are GMT -5. The time now is 07:15 PM.