|
Yeah, I was also amazed when I discovered it in a hidden place on the net...
|
|
|
|
|
Rajesh R Subramanian wrote: You mean... there's a documentation?
Yes, but only on days that end in Y.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi All
I am getting Debug Assertion failed.Message is here
Program: ...
File:f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h
Line: 876
Expression: nLength >= 0
and in the atlsimpstr.h file:
void SetLength( __in int nLength )
{
ATLASSERT( nLength >= 0 );
ATLASSERT( nLength <= GetData()->nAllocLength );
if( nLength < 0 || nLength > GetData()->nAllocLength)
AtlThrow(E_INVALIDARG);
GetData()->nDataLength = nLength;
m_pszData[nLength] = 0;
}
I could not figure out what the problem was from this output.
|
|
|
|
|
MsmVc wrote: I could not figure out what the problem was from this output.
You should try using your debugger and take a look at the call stack to see where to problemt relates to your code. Then you can set breakpoints just before the crash location and inspect the different variables to see if something is wrong.
|
|
|
|
|
thanks for reply.
How can i use debugger?Plz help me
|
|
|
|
|
You mean that for the last months that you are posting on CP, you never used your debugger ? Wow, time to get started on that I guess...
Using your debugger is not that difficult: simply set breakpoints by double clicking in the margin next to your code and press F5 to start the debugger. You'll need to investigate a bit yourself to see how it works.
|
|
|
|
|
This will help you in debugging [^]
|
|
|
|
|
Analyse the parameter nLength that you are passing to SetLength method. From the code-snippet,
ATLASSERT( nLength >= 0 ); // Line 876
ATLASSERT( nLength <= GetData()->nAllocLength );
it's clear that the nLength must be >= 0 and <= GetData()->nAllocLength.
You may not have properly initialized nLengh parameter.
|
|
|
|
|
MsmVc wrote: How can i use debugger?Plz help me
For the sake of God, please buy a beginners book on programming.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i have 3 projects included in my work space.when i release build them one of the projects cause link error 1257 code generation failed.No error comes in debug build.how can i remove the error in release build.
|
|
|
|
|
|
thanx it helped a little bit but dont tell how to overcome the problem.so the problem persists.
|
|
|
|
|
explain how far the problem is solved.
ali kanju wrote: helped a little bit
that statment is a little vague.
|
|
|
|
|
i mean it tells that it may be a linker problem...bt dont exactly tells how to overcome the problem..i have visual studio 2005 in use..
|
|
|
|
|
hi all,
people may feel that the question what i ask is very basic but guess what i didnt found the right answer for this
thats the reason i am posting here so please help me...
1. when we allocate 50bytes of memory via malloc or new
and while using free or delete[] on this variable how does it knows to delete all those 50 blocks.....
2.
<br />
int i = 10;<br />
int &a = i;<br />
a = 30;<br />
how does compiler knows that it need to change the value of i to 30.
please help me.......
|
|
|
|
|
1. The OS keeps track of all allocated blocks on the heap. So it knows about the total size, number of objects etc. This information is used to free the heap.
2. a is a reference to the variable i.
Even though references were introduced in C++, internally it is still implemented as a pointer.
So int &a = i; means pointer a that holds the address of variable i.
a = 30; means put the value 30 into the address where a is pointing to.
Since i is the variable assigned to that address, its value becomes 30.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: So int &a = i; means pointer a that holds the address of variable i
I doubt. I think reference is not a pointer, it is the object. See here[^].
|
|
|
|
|
Reference is not a pointer as far as the compiler is concerned.
After the compiler processes it, it is very similar to how a pointer is.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
N a v a n e e t h wrote: I think reference is not a pointer, it is the object
C++ references are implemented as a pointer - trust me
The only real differences between references and pointers are the syntax (. rather than ->) and the fact that it's very difficult to get a null reference - the language does it's best to ensure that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: C++ references are implemented as a pointer - trust me
Are you saying it is implemented as pointers behind the scenes? I have checked GCC's documentation and other pages. But couldn't find how they implemented it.
AFAIK, C++ standard doesn't tell anything about how a compiler should implement references. A pointer has a memory address and it's own space on the stack whereas a reference share the same address of the original variable. Also the statements in FAQ[^] and whatever you said is not matching (see the Important note specially). Or am I missing something here?
|
|
|
|
|
N a v a n e e t h wrote: Are you saying it is implemented as pointers behind the scenes
Yep - consider this C++ code - two equivalent functions, one using a pointer, the other a reference.
void Add1(int* pInt, int x)
{
*pInt += x;
}
void Add2(int& rInt, int x)
{
rInt += x;
}
I compiled this with cl -FAcs -c -O2 and got this assembly language (irrelevant bits snipped):
PUBLIC ?Add1@@YAXPAHH@Z ; Add1
_TEXT SEGMENT
_pInt$ = 8 ; size = 4
_x$ = 12 ; size = 4
?Add1@@YAXPAHH@Z PROC ; Add1, COMDAT
; 3 : *pInt += x;
00000 8b 44 24 04 mov eax, DWORD PTR _pInt$[esp-4]
00004 8b 4c 24 08 mov ecx, DWORD PTR _x$[esp-4]
00008 01 08 add DWORD PTR [eax], ecx
; 4 : }
0000a c3 ret 0
?Add1@@YAXPAHH@Z ENDP ; Add1
_TEXT ENDS
PUBLIC ?Add2@@YAXAAHH@Z ; Add2
_TEXT SEGMENT
_rInt$ = 8 ; size = 4
_x$ = 12 ; size = 4
?Add2@@YAXAAHH@Z PROC ; Add2, COMDAT
; 8 : rInt += x;
00000 8b 44 24 04 mov eax, DWORD PTR _rInt$[esp-4]
00004 8b 4c 24 08 mov ecx, DWORD PTR _x$[esp-4]
00008 01 08 add DWORD PTR [eax], ecx
; 9 : }
0000a c3 ret 0
?Add2@@YAXAAHH@Z ENDP ; Add2
_TEXT ENDS
END
Exactly the same code for each.
The Wikipedia page on C++ references[^] says it quite nicely - ...the typical implementation...effectively compiles references into pointers which are implicitly dereferenced at each use. Basically, references are (from most C++ programmers PoV) pretty much just syntactic sugar[^] for pointers.
PS - here's the gcc assembly language for that C++ code - again, the two functions are implemented exactly the same.
.globl __Z4Add1Pii
.def __Z4Add1Pii; .scl 2; .type 32; .endef
__Z4Add1Pii:
LFB2:
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl %eax, (%edx)
popl %ebp
ret
LFE2:
.align 2
.p2align 4,,15
.globl __Z4Add2Rii
.def __Z4Add2Rii; .scl 2; .type 32; .endef
__Z4Add2Rii:
LFB3:
pushl %ebp
LCFI2:
movl %esp, %ebp
LCFI3:
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl %eax, (%edx)
popl %ebp
ret
LFE3:
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
WOW! That's food for thought. Thanks. Let me investigate further on this.
|
|
|
|
|
Hi Stuart and Navaneeth,
I was browing old posts and came across this discussion. The standards state that It is unspecified whether or not a reference requires storage which gives compiler venders alot of room for implementation. However I believe you are both correct depending on how the compiler performs optimization and has implemented references. I make this assertion because the ISO standards explicitly allow both scenarios.
Essentially it is not correct to say that references are always pointers. It is equally incorrect to say that references always refer directly to the object. It really comes down to language semantics.
Best Wishes,
-David Delaune
|
|
|
|
|
hawk23reddy wrote: how does compiler knows that it need to change the value of i to 30.
Quoting C++ FAQ Lite[^]
Underneath it all, a reference i to object x is typically the machine address of the object x. But when the programmer says i++, the compiler generates code that increments x. In particular, the address bits that the compiler uses to find x are not changed.
Even though a reference is often implemented using an address in the underlying assembly language, please do not think of a reference as a funny looking pointer to an object. A reference is the object. It is not a pointer to the object, nor a copy of the object. It is the object.
|
|
|
|
|
1. The OS keeps track of all allocated blocks on the heap. So it knows about the total size, number of objects etc. This information is used to free the heap.
I doubt about it, according to my knowledge whenever application allocates memory using malloc or new, compiler will keep track of total amount of memory allocated in 4 bytes (32 bits on 32-bit OS) just ahead of starting address of allocated block.
For example, int *a = new int[4];
Suppose starting address of a is 100, then 4 bytes ahead of address location 100 say 96-100 will contain value 4*sizeof(int).
So when free or delete is invoked, it just look into memory space and release accordingly.
Hope this explanation will answer your question.
|
|
|
|