|
Michael P Butler wrote:
Previous projects have used Hungarian Notation but with all my C# work, I've sort of gone off it.
Your current style looks sort of Java-ish. Is this something that C# has advocated?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
sunit i quite right !
however, i could had this :
the most used is certainly the hungarian notation.
here is the main points to know about it.
a letter can prefix the name of a variable to show its type :
i or n integer
f float
d double
l long
c character
b boolean
dw double word
w word
by or byte byte
sz C-style null-terminated string
str C++ string object
h handle
v vector
pt point
rgb RGB triplet
p pointer to
r reference to
u unsigned
a or ary array of
m_ member variable
g_ global variable
s_ static variable
the name of an identifier must be the most explicit as possible.
you can find different styles, such as getMachineState(), GetMachineState(), get_machine_state(), etc...
upper case identifiers are in general for constants...
to this, there are also some specific rules, but the most important is that you should select your own, and follow them !
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 11:11 Friday 26th August, 2005
|
|
|
|
|
We use CamelCase for function and variable naming although variables always start in lower case while functions start in uppercase:
m_myVariable
MyFunction();
When you know the rule, you can tell at a glance whether its a function or a variable.
If you vote me down, my score will only get lower
|
|
|
|
|
got nice tips from u all..i think i need to change my style a lot.. thank u guys
thanx
V
|
|
|
|
|
How can I know that which Lan users are accessing the folders which I have shared?
|
|
|
|
|
Use NetShareEnum().
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I was freaked out with this code until went to disassembly
Find what you need to fix problem?
#include "stdafx.h"
class CA
{
public:
// do not add default constructor here
// solve problem with out it
CA(int nA)
{
m_nA = nA;
}
int m_nA;
};
class CB : virtual public CA
{
public:
CB(int nB) : CA(nB)
{
m_nB = nB;
}
int m_nB;
};
class CC : virtual public CA
{
public:
CC(int nC) : CA(nC)
{
m_nC = nC;
}
int m_nC;
};
class CD : public CC, public CB
{
public:
CD(int nD) : CC(nD), CB(nD)
{
m_nD = nD;
}
int m_nD;
};
int _tmain(int argc, _TCHAR* argv[])
{
CD oD(1);
//error C2512: 'CA::CA' : no appropriate default constructor available
return 0;
}
//funny ha?
-- modified at 10:21 Friday 26th August, 2005
|
|
|
|
|
Aha! This is obviously the classic "Diamond-of-Death" inheritance problem in the code. If you have this in your code, then you seriously need to rethink!
Joel Holdsworth
-- modified at 10:43 Friday 26th August, 2005
|
|
|
|
|
u should provide default contructor if you define argument contructor
|
|
|
|
|
Replace constructor declaration
CD(int nD) : CA(nD), CC(nD), CB(nD)
Just so simple
|
|
|
|
|
yes it will show error.u have to mention default construtor
CD(int nD) : CC(nD), CB(nD)
if u instantiated object of Class CD
say CD cd(4);
then both CC and CB( CC(int nC) : CA(nC) and CB(int nB):CA(nC)) will try to assign the data member of CA.whereas it is Virtually inherited in both Classes(CC,CB).So only one copy of Class CA has to be present.
-- modified at 11:10 Friday 26th August, 2005
|
|
|
|
|
Replace constructor declaration
CD(int nD) : CA(nD), CC(nD), CB(nD)
Just so simple
|
|
|
|
|
Replace constructor declaration
CD(int nD) : CA(nD), CC(nD), CB(nD)
Just so simple
|
|
|
|
|
from where does "new" operator allocate memory?
I don't know anything about memory management. I was only interested in "new" operator. but now I have encountered a lot memory allocation functions and I don't know their differences.
HeapAlloc, GlobalAlloc, AllocateUserPhysicalPages, ...
can you give a reference for me to understand them?
also, please say what is page?
|
|
|
|
|
Ali Tavakol wrote:
from where does "new" operator allocate memory?
the default 'new' calls nh_malloc / malloc, internally, which allocates memory from the heap.
Cleek | Image Toolkits | Thumbnail maker
-- modified at 9:58 Friday 26th August, 2005
|
|
|
|
|
|
In general it depends on the operating system and on the compiler version.
In Windows environment, new will typically relay on malloc (the good old C runtime), that hiddenly allocate from a local heap.
(C6 did it whith LocalAlloc , I did'nt look what's on C7: probaly HeapAlloc ).
The best way to detect this is (but you must be patient) to code a small program like
int main()
{ delete new int(0); }
and executing it with the debugger step by step going into the functions.
About "page": it is something that deal with the addressing architecture of the processor. It can be roughtly defined as the maxixmum amout of memory addresses you can span by changing the value of a single CPU register. But this definition may vary depending on the processor architecture.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote:
In Windows environment, new will typically relay on malloc
but new is re-entrant while malloc() isn't.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
On windows, reentrancy isn't a big issue since traps happen only in very well defined points (i.e. message pumps or waits). However, when using the multithreaded libraries, malloc is serialized.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
emilio_grv wrote:
C6 did it whith LocalAlloc
new: C6 does it with _nh_malloc.
malloc: C6 does it with _nh_malloc or _nh_malloc_dbg.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Yes, but _nh_malloc is an internal CRT function that call other internal functions.
Here's the call stack for a
int main() { delete new int(0); return 0; }
n1.exe!_heap_alloc_base(size=40)
n1.exe!_heap_alloc_dbg(nSize=4, nBlockUse=1, szFileName=0x00000000, nLine=0) n1.exe!_nh_malloc_dbg(nSize=4, nhFlag=1, nBlockUse=1, szFileName=0x00000000, nLine=0)
n1.exe!_nh_malloc(nSize=4, nhFlag=1)
n1.exe!operator new(cb=4)
n1.exe!main()
n1.exe!mainCRTStartup()
KERNEL32.DLL!796d893d()
and here's _heap_alloc_base next instruction
...
...
--> return <code>HeapAlloc</code>(_crtheap, 0, size);
}
Similarly, operator delete calls HeapFree .
The same program, after redefining new and delete as
void* operator new(size_t s)
{ return malloc(s); }
void operator delete(void* p)
{ free(p); }
drive towards the same _heap_aloc_dbg call.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote:
but _nh_malloc is an internal CRT function
I never said otherwise, I just said that new and malloc both call it.
call stack:
Interesting, I just single step throu a new and delete on C6 (again) while watching the call stack (on C6). _nh_malloc() makes calls to BCCORE and NTKERNAL, but gives no details as to what functions it is calling.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Under Win32, there is no difference between GlobalAlloc() and LocalAlloc() . They are only provided for compatibility to 16-bit Windows when there was a global and a local heap.
malloc() is a wrapper around HeapAlloc() , which in turn is a wrapper around VirtualAlloc() . I believe this was mentioned in Richter's book "Advanced Windows."
One thing that the new operator does that none of the others do is call an object's constructor and destructor.
See here for more.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
DavidCrow wrote:
One thing that the new operator does that none of the others do is call an object's constructor and destructor.
That's partially correct.
operator new just returns a void* to uninitialized memory. (note that new parameters don't carry the object type)
The constructor is called after operator new returns, in a new expression, like ptr = new myclass .
The compiler tranlsates this into
(ptr = (myclass*)operator new(sizeof(myclass))))->_ctor();
(assuming no myclass::operator new exist)
Although this behavior may seem a bit obscure, it allows operantor new to be inherited, overloaded and base-called. The _ctor gets called only after all the "new" stuff is ended.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
I want to add a "time receiver" in my application, similar to that in "date and time properties" of windows control panel.
it has an editbox and some static classes and some edit controls that show time and can be modified with a small scrollbar.
how edit-class is added to this edit box to show time numbers?
|
|
|
|