|
That's partially correct.
The "string" litteral, in fact, stays in the BSS segmment (where all costant reside on the disk), loaded in memory as part of the EXE and exist for the entire life of the process.
It's acessiblilty happens trhoug an on-stack variable that is declared as a pointer to the BSS (first case) or as an array (on-stack) that is a copy of what stays in the BSS.
The most of the compiler optimize this (unspec. array size) by transforming such array into ... a pointer(!)
Just try to watch in the debugger what the pointer points to and what is the array address in bopth the case you don't declare a size or you do.
Then, declare an int just before the array and look its address: is it 4 bytes before the first array element?
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
|
See here.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hello folks, I need your help:
I need to know the Ethernet Permanent Mac Address
and I would like to know how to detect if a ethernet
card is :
1) removable (tipical of laptop) or fixed (on the bus)
2) on board on a dockin station
3) avoid mac addres like 00-53-45-00-00-00 (wireless
card??)
Im work with devstudio C++ 7.1
Can you help me ?its very urgent
Thank you a lot in advance for any suggestion/help
Mario
|
|
|
|
|
|
Dear All.
I want to write the MATLAB function cp2tform in C/C++.
Can anyone help me out with the logic.
Precisely , I want to implement the projective transformation. So if there is any other algorithm then also suggest me.
Thanks in advance.
Arun
|
|
|
|
|
Hi all,
What does the WaitForDebugEvent function do? I read it in MSDN, but didn't get a clue as to what it does? Can someone explain?
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
I think tihs function is only required if u r creating some debugger related stuff.
See the remarks section in MSDN.
Only the thread that created the process being debugged can call WaitForDebugEvent
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
|
|
#include <stdio.h><br />
<br />
int *pPointer;<br />
<br />
void SomeFunction()<br />
{<br />
int nNumber;<br />
nNumber = 25; <br />
<br />
pPointer = &nNumber;<br />
}<br />
<br />
void main()<br />
{<br />
SomeFunction();
<br />
printf("Value of *pPointer: %d\n", *pPointer);<br />
}
Hi friends,
the above code is working without any problems in VC6.
But it should fail at the line printf("Value of *pPointer: %d\n", *pPointer);
because pPointer is pointing to a local variable,which is already deleted.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
the pointer points to an address that is not overwritten yet, so you still see 25 displayed. however, this code is not safe because if the system had given this memory area to another process, you would have accessed a memory area you don't own (which results in an access violation) !!!
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
toxcct wrote: the pointer points to an address that is not overwritten yet, so you still see 25 displayed.
But when we observe the value of nNumber ,it is not showing any value.
But a pointer(pPointer) is a variable which refers another variable(nNumber),
So it should crash at that point..But it is not .Why ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
HI NiceNaidu
I think the reason why this is working fine is that you have declared the integer pointer (int *pPointer ) globally. So once you point it to some memory location it will keep pointing to that location untill the program terminates. So whenever you try to print its value it will print it without any problem.
Rakesh
|
|
|
|
|
no !
the pointer variable is global, that mean its content only (address stored), but not the memory pointed...
read my 1st answer to undertand the reason why it's working.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Whats the difference detween address stored and memory pointed?
Because once you assign the address of any variable to any pointer then its contents are the memory location of that variable.
Rakesh
|
|
|
|
|
Rakesh_Thakur wrote: Whats the difference detween address stored and memory pointed?
the pointer stores the memory pointed...
pointer int pointed
----- ------
| * | ------> | 25 |
----- ------
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Thats what I am trying to say.
Contents of pointer are the memory location.
Contents of variable are the actual value.
nNumber is global which means it can be access only within its scope.
Once you come out of that function, scope of that variable ends which means you cannot access it or it is undeclared.
But the value stored at that memory location remains untill it has been over written.
In other words 'Memory is taken away from the variable but the momory contents are unchanged'. And as you are having a pointer to point at that mmory location, you can always get the content at that location.
Rakesh
|
|
|
|
|
Rakesh_Thakur wrote: nNumber is global which means it can be access only within its scope
that's totally wrong...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Sorry I wanted to write "The nNumber is local"
i.e.
nNumber is local which means it can be access only within its scope.
Once you come out of that function, scope of that variable ends which means you cannot access it or it is undeclared.
But the value stored at that memory location remains untill it has been over written.
In other words 'Memory is taken away from the variable but the momory contents are unchanged'. And as you are having a pointer to point at that mmory location, you can always get the content at that location
Rakesh
|
|
|
|
|
And as you are having a pointer to point at that mmory location, you can always get the content at that location
- ONLY if your process owns that memory location and it is readable. Otherwise, you get an access violation error of type 5.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
toxcct wrote: the pointer variable is global, that mean its content only (address stored),
So, what does u mean by dying of a local variable??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Dying of local variable means you its scope ends.
That varible is like undeclared outside its scope.
When you declare a variable, some memory location is assiged to it.
That memory location is now belongs to that variable.
And when that variable goes out of scope, that memory location is taken back from that variable i.e. the contents at that memory are still there but that memory location is now doesn't belongs to that variable.
Rakesh
|
|
|
|
|
Pointer is a global one.
But nNumber is a local one,which dies as soon as it come out of the function scope.
So, whenever we point to a variable which is already deleted,it should give an error.
Is this a problem with Microsoft compiler ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
nNumber is global which means it can be access only within its scope.
Once you come out of that function, scope of that variable ends which means you cannot access it or it is undeclared.
But the value stored at that memory location remains untill it has been over written.
In other words 'Memory is taken away from the variable but the momory contents are unchanged'. And as you are having a pointer to point at that mmory location, you can always get the content at that location.
Rakesh
|
|
|
|