|
always use inline ( or ordinary methods ).
the only reason I can give is that macros are preprocessor stuff and are not "debuggable"
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
the only reason I can give is that macros ... are not "debuggable"
That should be reason enough. Very few things should exist as a preprocessor macro. The ability to type-check parameters is a must.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
My general rule is that if it can be done as an inline function, it should be.
There are some things which cannot be done with an inline function, but can be done with a macro. Those are rare, though.
|
|
|
|
|
avenger_sb25 wrote:
Hi geeks,
That's a wee bit rude, don't you think?
avenger_sb25 wrote:
I need an answer comparing the two. Please dont post definitions of macro and inline function as i am aware of them. Please give the answer in terms of efficiency, speed, code-size, pre-compilation/post-compilation, and things like that.
And please give examples ...
This sounds suspiciously like you've got a take-home exam in a programming course, and you're looking for us 'geeks' to provide the answers.
I'll give you the answer to your question. My rate is $75USD/hr (you're getting the student discount, BTW), 4 hours minimum, in advance, in cash.
Software Zen: delete this;
|
|
|
|
|
Is that something you say when you dont know the answer Mr?
Anyway a proper answer would have been appreciated. I was asked this questionj at a job interview. When i will get the job, i will pay u. LOL
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi einstines,
i was asked this question at an interview:
class a<br />
{<br />
};<br />
main()<br />
{<br />
cout<<sizeof(a); <br />
}
I can obviously run the program to find the output but i need an explanation about the output.
PLEASE ANSWER: WHAT IS THE OUTPUT????
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
i did just that in VC++
class A
{
};
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int i = sizeof(A);
cout << "Sizeof A:" << i << endl;
}
it displayed 1.
I switched to assebmly listing and the linker has generated the following code:
77: int i = sizeof(A);
004018AB mov dword ptr [i],1 <----- Notice here, the linker knew its an empty class and automatically replaced its size by 1
78:
79: cout << "Sizeof A:" << i << endl;
004018B2 mov esi,esp
004018B4 mov edx,dword ptr [__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z
004018BA push edx
004018BB mov edi,esp
004018BD mov eax,dword ptr [i]
004018C0 push eax
004018C1 mov ebx,esp
004018C3 push offset string "Sizeof A:" (004130d4)
004018C8 mov ecx,dword ptr [MSVCP60D_NULL_THUNK_DATA (00415234)]
004018CE push ecx
004018CF call dword ptr [__imp_??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z (004
004018D5 add esp,8
004018D8 cmp ebx,esp
004018DA call _chkesp (004014bc)
004018DF mov ecx,eax
004018E1 call dword ptr [__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z (0041523c)
004018E7 cmp edi,esp
004018E9 call _chkesp (004014bc)
004018EE mov ecx,eax
004018F0 call dword ptr [__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01
004018F6 cmp esi,esp
004018F8 call _chkesp (004014bc)
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Ya, thanx for ur reply and to tell the technique to see linker output (thats a new thing i learnt)
But, why 1? is it property of the linker or a C++ standard to make size of an empty class as 1. Please tell.
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Never tested it on unix, but one thing im sure of, is that empty structs are forbidden if you compile the file as a c file and not as a cpp.
However while permitting generation of an empty class, the linker is forced to allocate some space for it (vtable ...) and cos its empty, sizeof just returned the minimal size reserved for a class.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
VTable is only allocated if the class actually contains virtual functions.
The size of an empty class will always be greater than zero because two objects must not occupy the same space. (As DavidCrow pointed out)
|
|
|
|
|
avenger_sb25 wrote:
WHAT IS THE OUTPUT????
It won't be zero, as that would allow two different objects to have the same address. If sizeof(a) returned 0, then the following would be allowed:
main()
{
a a1, a2;
if (&a1 == &a2)
...
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
From the Standard (1.8.5)
Unless it is a bitfield, a most derived object shell have a non-zero size and shell occupy one ore more bytes of storage. Base class sub-objects may have zero size.
|
|
|
|
|
Base class sub-objects may have zero size
Can u please give a working example. I did
class p<br />
{<br />
};<br />
class q: public p<br />
{<br />
};<br />
p o1;<br />
q o2;<br />
cout<<sizeof(o1);<br />
cout<<sizeof(o2);
I get 1 in both. Thank you.
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
how do i place a image next a menu
Clint
|
|
|
|
|
What about this[^]
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
thank you for your reply but, these examples are all part of the toolbar not nex to the toolbar.
Clint
|
|
|
|
|
huh ?
what exactly do you want ? a popup/drop down menu in a toolbar ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
something that looks like a standard menu ie File,edit,options but can have a large picture, on the left which may, or may not overlap the toolbar.
Clint
|
|
|
|
|
I have a quick question regarding saving font settings in a drawing type package.
For example, an application like Corel Draw who has a TextBox on the canvas who uses Arial font, how would that information be saved?
Obviously, we'd store the text in some kind of string/char object, but for the font, would you just store the szFontName, nPointSize and some style bits (bold/italics/underline)?
We're working on an issue with our product where somebody has chose to save the LOGFONT structure, but we're finding that the logfont.height guy is based on the DC because of the call:
logfont.lfHeight = -MulDiv ( PointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72 );
Bottom line, Whats the common way to save this stuff?
Any info you could send would be greatly appreciated.
Mike.
|
|
|
|
|
I would save the font height in typographical points - that is, PointSize rather than logfont.lfHeight above.
You might want to consider using CreatePointFontIndirect for font creation, then you can save/load the LOGFONT directly.
|
|
|
|
|
excerpted from MSN" The user scrolls the content of a window by clicking one of the arrow buttons, by clicking the area in the shaded shaft, or by dragging the scroll box. When the user clicks an arrow button, the application scrolls the content by one unit (typically a single line or column). "
Question: how to retrieve the size (by pixel) of a unit?
ZZH1234567@HOTMAIL.COM
|
|
|
|
|
have a look at CScrollBar::GetScrollInfo and the SCROLLINFO struct.
also, depending on the application, it can be user/programmer defined, for example, if you need to scroll a bitmap, you can set the "unit" to 1 pixel, or if it's text, you can compute it to scroll the height of the next/previous line.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Hello
I'm writing a class derived from MFC's CTime with additional methods for my
app but have a problem.
Time variable in base class is declared as follows:
private:
time_t m_time;
Is there any 'magical c++' trick to access it in derived class?
(without changing base class of course)
For now i see only two options (not deriving):
Rewrite entire class
or put CTime in new class as a member and do some tricks with all required methods.
But maybe someone hava a better idea?
thanks
Chris
|
|
|
|
|
no trick needed ....
use the GetTime method from CTime to get m_time.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
well, i didn't say i cannot get this value. i want my class to derive all
methods, operators from CTime and work well with CTimeSpan also.
I have written a method like this:
bool CTimeEx::SetYear(int nYear)
{
time_t c_time;
struct tm *atm;
c_time = GetTime();
...
...
...
return TRUE;
}
but GetTime() don't work here. When i debug there is an error like this:
code:
_AFX_INLINE time_t CTime::GetTime() const
{ return m_time; }
m_time | CXX0069 Error: variable needs stack frame
it's because of inline i think
any more help?
thx
|
|
|
|