2

I need to know how to convert any #define for .c (source) and .h (header) files.

#define ELAPSED_TIME(currentTime, startTime) (currentTime - startTime)
2
  • What do you mean by convert? If you mean replace then that can be done in pre-compile step e.g. gcc -E my_source.c Commented Aug 14, 2018 at 11:07
  • 3
    Add suitable types, braces, return, and a semicolon. (That particular macro is broken, by the way. ELAPSED_TIME(3, 1+1); should be 1, but is 3.) Commented Aug 14, 2018 at 11:11

2 Answers 2

3

for example:

int elapsed_Time (int currentTime, int startTime)
{
    return (currentTime - startTime);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Preprocessed macros are simply text replacement , so if you convert such macro in function then you must bind it with some type , here looking at macro definition I am not sure generic (void*) type will work here. In c++ you can templatise the same, but this is simply replacement so if you have genric usage like for float/char/int/uint/long so better to keep it or templatize it in c++ or use (void*) in c function and do the subtraction on lowest unit level (eg char by char ).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.