|
GAJERA wrote: Though why we use MACRO and INLINE? or what is advantage of it.
You're really comparing apples to oranges. While you can make the #define preprocessor directive look like a function (e.g., min() , max() , HIWORD() ), there's nothing functional about it.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
GAJERA wrote: When we write definition of function in .h file.It's automatic a inline function consider by compiler.
This does not make sense, a function definition is merely a hint to the compiler so that it can generate the correct code for a function call in the code. It has nothing to do with either inline or macros.
GAJERA wrote: what is difference between Inline and MACRO as speed and execution?
They are totally different beasts so you cannot compare them. The inline keyword tells the compiler to generate the code 'inline' rather than via a function call. A MACRO is used to generate (possibly) different source language from parameters in the macro call. The modified source is then compiled to object code and may be inline or include function calls.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
GAJERA wrote: When we write definition of function in .h file.It's automatic a inline function
No it's not - if that's what your book said it was probably written by Herb Schildt and should be consigned to the bin. There are two ways of getting a function expanded inline:
- explicitly qualify it's definition with the inline keyword
- define a function in the body of a class
In both cases it's at the discretion of whoever wrote the compiler. If their cost/benefit analysis reckons there's no gain to be had by inlining the function the compiler won't do it. [Likewise there's no reason why a compiler and linker can't conspire to do inlining across modules - VC++ has done that for years...]
Personally I only ever use inline functions when writing templates, otherwise I don't bother so the size of the functions that may or may not be inlined is a problem for someone else. Likewise with macros - I only ever use them if there's no other option within the programming language. Inline functions are usually a better bet as they're processed by the compiler and it can give you far more meaningful error messages than the preprocessor does. Execution speed wise it's impossible to say in the general case.
Ash
|
|
|
|
|
The Macro is dealed with the preprocessor, it is only text replace. Because the C language does not have const keyword. so coder uses the Macro to define the const. And the function defined too. The head file can use #define to define a macro to forbide one head file included more than once in a project. Now the Visual studio 2005 can use #prama once instead of it.
The preprocessor cannot check the Macro type. so some error happens because for the Macro.
The inline can let function defined inside class.
Because one function called, it need to do jump, push stack, pop stack operations. So if some function simplely processes data and is called frequently, you can define this function as inline function to reduce the time used to call method. The incline funciton will be expansion by processor in the function called position. After compiled, you cannot find the inline function name.
I use inline function to cout the size of a struct.
About the speed, I donot test which is more quickly. But the c++ suggests not to use the macro. It often leads to error.
|
|
|
|
|
I would like to make a shortcut key combination to output test.
I have not had any luck finding any example code.
I know how to send text to the clipboard, but I have 4 sets of different text
that I want to use.
For example Ctrl Alt I would send "PPPPP is a good plan" to a storage area where I could
do a Shift Insert to place the text in an open document.
I have a list of Windows Shortcut keys so I would not "tromp" over those combinations.
Can someone help me?
Thanks.
|
|
|
|
|
Here is something you could try.
Use RegisterHotKey to register the shortcut keys.
Remember to specify a handle to a window as the first parameter.
When the windows receives the WM_HOTKEY message, use WM_SETTEXT to send a text to the active window.
You can use GetForegroundWindow to get the window with which the user is currently working.
|
|
|
|
|
I have been doing MFC coding. I am learning to do some STL lately, which Template project is the best for STL coding? is it ATL?
Thanks
|
|
|
|
|
(If I got you) You may do whatever project you like (even MFC !) using profitably the STL library.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes. Even though I did some STL, vectors and Lists coding within MFC, I ran into no problems there. However, I do see on the web lots of talk about not mixing the two up, so I was wondering about the ideal situation for STL.
Thank you
|
|
|
|
|
There might be some situations where you need to use a MFC collection because an existing MFC API needs it, but that's quite rare.
In general, STL is very friendly with different kind of C++ environments.
Watched code never compiles.
|
|
|
|
|
Any C++ project will do fine.
No need for ATL.
you just have to include necessary headers in stdafx.h.
Watched code never compiles.
|
|
|
|
|
STL is the C++ Standard Template Library and it offers a number of useful facilities for coding in C++. It has no connection with either MFC or ATL, both of which are concerned with Windows Programming. Spend some time learning STL and how to apply it to your applications, whether they are console, ATL Windows, Win32 Windows or MFC Windows.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
All good answers. I will spend some time learning STL.
|
|
|
|
|
Other than CString (and not std::string) I use STL for everything else.
std::string is terribly bad!
For non-MFC project, you just need to include atlstr.h for CString (no DLL required).
|
|
|
|
|
Ajay Vijayvargiya wrote: std::string is terribly bad!
I'd be interested to know why, especially as I do not have access to MFC.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Richard MacCutchan wrote: I'd be interested to know why, especially as I do not have access to MFC.
For one, it does not support direct conversion to plain C-style strings. You must call set of methods. It does not support Format/sprintf type of functions, not methods to convert to upper/lower, methods to trim, convert from Unicode/ANSI string and things that should be part of a good "string manipulation class". See wxString, which I prefer over CString!
|
|
|
|
|
Ajay Vijayvargiya wrote: For one, it does not support direct conversion to plain C-style strings
Which is good, because it saves you from a whole class of subtle bugs. Explicit conversion is always better than implicit.
Having said that, I don't like std::string either - it is an example of monolithic design[^]. But that does not mean CString is any better.
|
|
|
|
|
Nemanja Trifunovic wrote: an example of monolithic design[^]
Excellent article, thanks,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Nemanja Trifunovic wrote: Which is good, because it saves you from a whole class of subtle bugs. Explicit conversion is always better than implicit. Heard of this umpteen number of times, but doesn't appease me at all. I am using a string-class for string, a text, and in C/C++ code it is supposed to mix with C-Style strings. The conversion is implicit to C-string and not from a C-string. You cannot assign a CString to char*/ wchar_t* , the compiler wont be happy. If you say you can put into const char*, and then do forceful conversion, then my friend, you are placing the so called "bug" by yourself.
I mean, what a vector<char> would be called other than std::string ? A good string-class must have string operations. Even in case, I wont have access to CString, I would write my own string-class, or download code written by some expert, instead of using this absurd std::string !
Nemanja Trifunovic wrote: But that does not mean CString is any better. Any better, compared to what?
|
|
|
|
|
I tend to use the console application template and start by removing everything I don't want, so CLR support, stdafx.h etc...
|
|
|
|
|
if you want to use std::string, the best way to get into that is to redefine your string type with something like this:
typedef std::basic_string<tchar, std::char_traits<tchar="">, std::allocator<tchar> > tstring;
typedef std::basic_stringstream<tchar, std::char_traits<tchar="">, std::allocator<tchar> > tstringstream;
using it you dont have to worry if using unicode or ansy character sets
it's really useful!
Saludos!!
____Juan
|
|
|
|
|
Beware useing <and > in messages, since HTML mess them up!
I try to rewrite your message properly. Correct me if I misinterpret.
"
if you want to use std::string , the best way to get into that is to redefine your string type with something like this:
typedef std::basic_string<TCHAR,std::allocator<TCHAR> >tstring;
typedef std::basic_stringstream<TCHAR, std::allocator<TCHAR> > tstringstream;
using it you dont have to worry if using unicode or ansy character sets
"
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Visual Studio 2010, Windows 7 645 bit.
Objective: Create a CMap Object, store info and retrieve later.
We have (out of context):
typedef CMap<int, int, DWORD*, DWORD*> map_OpenObj;
........................................................................................
map_OpenObj* p_mapObj = NULL;
p_map = new p_mapObj;
........................................................................................
nIdx = some integer;
p_dwObj = (DWORD*)(pointer to some object);
m_pOpenObjMap->SetAt(nIdx, p_dwObj);
.......................................................................................
The above compiles, links and executes without incident with one exception. Later in the application I have:
int nCount = 0;
POSITION posPos = NULL;
nCount = m_pOpenObjMap->GetCount();
posPOS = m_pOpenObjMap->GetStartPosition();
I get nCount = 1, which I would have expected, however posPOS comes back = 0xffffffff, which it shouldn't. This has worked before under Visual Studio 2008. Note: In the application, m_pOpenObjMap will never see ARG or ARG_KEY contain the same values.
The question is what am I doing incorrectly? Any thoughts?
Thanks, Barry
|
|
|
|
|
These words in the documentation[^]
The iteration sequence is not predictable; therefore, the "first element in the map" has no special significance.
look interesting.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Please allow me to take this to the next level. The map is used to hold class pointers cast to (DWORD)*. When retrieved (CMap->Lookup(...)), they are cast back to theit original type and used. The number of elements at any given point in time in the map varies depending upon how many classes have been created or destroyed. When the application closes, the remaining map entries are cast back to their original pointers then deleted; the map is then destroyed. Obviously, if I just destroy the map, I am left with memory leaks of varying classes.
The question occurs when I am down to just one map entry and it is time to close the application and destroy the last pointer cast DWORD*. How do I retrieve the last remaining item in the map?
|
|
|
|