Click here to Skip to main content
15,891,976 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: managing objects derived from the same base class using a container Pin
Calin Negru12-Aug-22 18:58
Calin Negru12-Aug-22 18:58 
GeneralRe: managing objects derived from the same base class using a container Pin
Richard MacCutchan12-Aug-22 21:55
mveRichard MacCutchan12-Aug-22 21:55 
Questionmoving graphics in a win32 c++ window Pin
Calin Negru9-Aug-22 8:25
Calin Negru9-Aug-22 8:25 
AnswerRe: moving graphics in a win32 c++ window Pin
Gerry Schmitz9-Aug-22 9:15
mveGerry Schmitz9-Aug-22 9:15 
AnswerRe: moving graphics in a win32 c++ window Pin
Graham Breach9-Aug-22 20:54
Graham Breach9-Aug-22 20:54 
AnswerRe: moving graphics in a win32 c++ window Pin
Richard MacCutchan9-Aug-22 20:57
mveRichard MacCutchan9-Aug-22 20:57 
GeneralRe: moving graphics in a win32 c++ window Pin
Calin Negru10-Aug-22 1:58
Calin Negru10-Aug-22 1:58 
GeneralRe: moving graphics in a win32 c++ window Pin
Richard MacCutchan10-Aug-22 2:01
mveRichard MacCutchan10-Aug-22 2:01 
QuestionFileMapping book exmple goes in loop Pin
coco2438-Aug-22 8:48
coco2438-Aug-22 8:48 
AnswerRe: FileMapping book exmple goes in loop Pin
Mircea Neacsu8-Aug-22 10:35
Mircea Neacsu8-Aug-22 10:35 
GeneralRe: FileMapping book exmple goes in loop Pin
coco2438-Aug-22 11:45
coco2438-Aug-22 11:45 
GeneralRe: FileMapping book exmple goes in loop Pin
Mircea Neacsu8-Aug-22 11:47
Mircea Neacsu8-Aug-22 11:47 
Questiondefining a function with #define Pin
coco24330-Jul-22 9:03
coco24330-Jul-22 9:03 
AnswerRe: defining a function with #define Pin
Mircea Neacsu30-Jul-22 9:54
Mircea Neacsu30-Jul-22 9:54 
No, it is not a function, it is a macro definition. While, in your case a function defined as:
C++
int evenbyte (int i) {return (i+7)/8*8;}
would do the same thing, there is an important difference: a macro definition is expanded at compile time while a function is compiled and later on called at runtime.

When to use one over the other is a question of optimization speed vs memory: a macro definition like your would not incur the overhead of a call but might produce larger code. Meanwhile a function definition would produce smaller code but might take longer to execute.

To solve these type of issues, C++ has introduced inline functions, so in C++ you can write
C++
inline int evenbyte (int i) {return (i+7)/8*8;}
and you leave the compiler the choice of expanding it inline (like a macro definition) or make it a function and call it.

One more thing: the macro definition is insensitive to the type of argument. That is both a good thing and a bad thing like in the examples below:
C++
int i1 = 3;
int e1 = EVENBYTE (i1); //calling macro with an int argument yields an int result
long i2 = 129;
long e2 = EVENBYTE (e2); //calling macro with a long argument yields a long result

int e3 = EVENBYTE ("abc"); //generates some obscure error message

To accomplish the same thing in C++ you would have to use a function template:
C++
template <typename T>
T evenbyte (T i) { return (i+7)/8*8;}

Mircea

GeneralRe: defining a function with #define Pin
trønderen30-Jul-22 12:46
trønderen30-Jul-22 12:46 
GeneralRe: defining a function with #define Pin
Greg Utas30-Jul-22 13:58
professionalGreg Utas30-Jul-22 13:58 
AnswerRe: defining a function with #define Pin
Randor 30-Jul-22 9:55
professional Randor 30-Jul-22 9:55 
GeneralRe: defining a function with #define Pin
coco2433-Aug-22 9:01
coco2433-Aug-22 9:01 
QuestionHow to read an xlsx file using CDatabase Pin
Sampath57927-Jul-22 19:54
Sampath57927-Jul-22 19:54 
AnswerRe: How to read an xlsx file using CDatabase Pin
Victor Nijegorodov27-Jul-22 20:07
Victor Nijegorodov27-Jul-22 20:07 
GeneralRe: How to read an xlsx file using CDatabase Pin
Sampath57931-Jul-22 23:27
Sampath57931-Jul-22 23:27 
GeneralRe: How to read an xlsx file using CDatabase Pin
Richard MacCutchan31-Jul-22 23:38
mveRichard MacCutchan31-Jul-22 23:38 
AnswerMessage Closed Pin
31-Jul-22 17:19
Sampath57931-Jul-22 17:19 
GeneralRe: How to read an xlsx file using CDatabase Pin
Dave Kreskowiak31-Jul-22 17:30
mveDave Kreskowiak31-Jul-22 17:30 
GeneralRe: How to read an xlsx file using CDatabase Pin
Sampath57931-Jul-22 23:40
Sampath57931-Jul-22 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.