|
In standard C++ it isn't possible.
As Richard mentioned you can specify an entry point for MSVC and other linkers allow you to do the same thing but you'll have a few hurdles to jump:
- The parameters to whatever function you define as the entry point will probably not be argc and argv
- Depending on the start-up code you're avoiding static and global objects may not be initialised (no great loss though)
- The language runtime library, even if linked, probably won't be initialised
- Anything that relies on the OS interacting with the language might go screwy (e.g. if new/delete expects allocations to come out of a heap the runtime allocates on start-up)
About the only place I've used this trick, had it work and be useful was back programming for Windows 3.1 when I was trying to keep the size of code down to a minimum and I was willing to pay the price for having an emasculated language. Basically if you're happy programming in assembler and using the OS and your own code for everything then then it may have some use.
|
|
|
|
|
Hi Mr. Univoter, any chance you can tell me why you voted me down? This is so I can either/or:
- improve my answer and perhaps leaarn how to express myself better next time
- learn something
- disagree with you and say why and let other people make up their mind
I don't do tit for tat univoting so don't let that stand in your way!
Ash
|
|
|
|
|
Hello All,
I have a hang dump from client. But the corresponding pdb are not available as it is a legacy project.
Is it possible to know whether my components are responsible for this hang without pdb's.
Thanks in advance.
|
|
|
|
|
It is possible, but without the PDB file, you will have to deal with memory addresses instead of symbols during analysis.
It would take more time and patience, but it is definitely possible.
All the best.
|
|
|
|
|
Hi,
is there any good tutorial on how to analyze hang dump when there is no PDB. I googled but failed to get good one.
Thanks for your help
|
|
|
|
|
To a certain extent, yes.
You need to set windbg to use Microsofts public symbol server, look in Windbg Help for symsrv.
this will suck down pdbs for all MS components leaving yours and third party ones. Hopefully, you can see in the stack where your code is calling into MS code and therefore what part is hanging.
of course you should archive all pdb files with the built exes.
==============================
Nothing to say.
|
|
|
|
|
#include <iostream>
#include <stdlib.h>
#include<ctime>
using namespace std;
void makebg(char**&);
bool Is(int ,int );
void cmaze(int,int);
void count(int,int);
int M=0;
int N=0;
int in=0;
int out=0;
char **maze;
int c=0;
int *cti;
int *ctj;
int dir =1;
int main()
{
cin>>M>>N;
maze =new char*[M];
for(int i=0;i<M;i++)
maze[i]=new char[N];
cti =new int[M*N];
ctj =new int[M*N];
for(int i=0;i<M*N;i++)
{
cti[i]=0;
ctj[i]=0;
}
makebg(maze);
return 0;
}
void makebg(char **&maze)
{
int i,j;
for(i=0;i <M;i++)
for(j=0;j <N;j++)
maze[i][j]='#';
srand((unsigned)time(0));
in=rand()%(M-2)+1; maze[in][0]='.';
out=rand()%(M-2)+1;
cti[0]=in;
ctj[0]=1;
cmaze(in,1);
}
void cmaze(int i,int j){
int ran=rand()%4;
if((i==out&&j==N-2)) {
maze[i][j]='.';
maze[i][j+1]='.';
}
if(maze[out][N-1]=='.')
return;
else{
maze[i][j]='.';
for (int s=0;s<M;s++)
{
for (int t=0;t<N;t++)
cout<<maze[s][t]<<' ';
cout<<'\n';
}
switch(ran)
{
case 0:{
if(Is(i+2,j)&&Is(i+1,j-1)&&Is(i+2,j+1)){ i++;
count(i,j);
dir=2;
}
else if(i+1==M-1) { c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0;
}
break;
}
case 1:{ if(Is(i,j-2)&&Is(i+1,j-1)&&Is(i-1,j-1)){
j--;
count(i,j);
dir=3;
}
else if(j-1==0){
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0;
}
break;
}
case 2:{ if(Is(i-2,j)&&Is(i-1,j-1)&&Is(i-1,j+1)){
i--;
count(i,j);
dir=0;
}
else if(i-1==0){
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0;
}
break;
}
case 3:{ if(Is(i,j+2)&&Is(i-1,j+1)&&Is(i+1,j+1)){
j++;
count(i,j);
dir=1;
}
else if(j+1==N-1){
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0;
}
break;
}
}
dir=ran;
cmaze(i,j);
}
}
void count(int i,int j)
{
c++; cti[c]=i; ctj[c]=j;
}
bool Is(int i,int j)
{
if(i>=0&&i<=M-1&&j>=0&&j<=N-1&&maze[i][j]=='#')
return true;
else
return false;
}
what's the problem of my code?? can't create the maze.
may be problem comes from back to previous step,but how to correct it?
|
|
|
|
|
jiuyejii wrote: what's the problem of my code??
what happens when you run it?
|
|
|
|
|
the error : stack overfow ,or can not return to the previous step so can't find the exit
|
|
|
|
|
jiuyejii wrote: what's the problem of my code?? can't create the maze. may be problem comes from back to previous step,but how to correct it? You seriously need to learn to use the debugger to help solve such problems. Dumping a boatload of code in a forum and asking others to wade through it will get you nowhere.
Instead of trying to solve the problem as a whole, break it down into smaller chunks. If stack space is being exhausted, you most likely have a recursion problem.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
did you debug with a small maze size?
do you check array boundaries ? (for example in function count ).
You should try to convert the recursion to a iterative (loop); it might help fix the stack overflow.
Watched code never compiles.
|
|
|
|
|
No idea what's causing your stack overflow, but as one of the previous posters mentioned (think it was David, sorry if I've got that wrong) it's probably related to recursion.
As to what the problem is with your code I can sum that up in one word. Abstraction. There's not a lot is there? When you write huge lumps of code how are other people meant to follow what you mean? Come to think of it how are you supposed to be able to follow it next week? And if you and other people are having problems think of the poor, literal minded compiler, he's having a nightmare [1].
So even if you don't want to do the whole OO thing, think about splitting your code up into nice little packets you and the rest of the world can understand. Here are some guidelines which have served me well:
- make each function only do one thing but make it do it well
- split loops and complex conditionals out into their own functions
- if a variable name is only a couple of characters long it's almost always too short
- if you've got more than 2 levels of indirection in an expression then that's too much. If you've got 2 it's probably still too much. Things like char **& are right out
- even if you're programming in "C like" C++ don't play about with memory directly. Let someone else do the heavy lifting. std::vector, std::unique_ptr and std::shared_ptr can cover about 99% of your dynamic memory requirements.
Interestingly you've got one complex conditional in it's own function. Cool! Keep that up and look for other places you can do the same sort of thing. FREX you've got the following segment of code:
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0; in four places. Think of a name to describe what this lot is up to and pack it away in a function. Do that a few more times and you might be starting to see where your code is going wrong.
[1] I've committed a cardinal sin here, I've anthropomorphised a computer. They don't like it when you do that.
|
|
|
|
|
Aescleal wrote: I've anthropomorphised a computer. They don't like it when you do that. No wonder OP has a stack overflow, with recursion like that!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you for your advice
|
|
|
|
|
|
The problem is right at the end of the function cmaze() : there you call the same function, recursively. That means for every step, your program will push one more function call on the stack, and it won't resolve it until the very end.
Don't do that kind of thing. Instead use the return code to indicate whetehr or not you need to do another step, and create a loop:
Change the function cmaze to:
bool cmaze(int& i, int& j) {
if (maze[out][N]=='.')
return false;
return true;
}
Change your call to cmaze in makebg() to:
i = in;
j = 1;
while (cmaze(i, j));
|
|
|
|
|
You are right and your suggestions let me learn more,thanks
|
|
|
|
|
i took an MFC application written in VS2010
opened in in win8 with visual studio 2012
got the following errors:
error C1083: Cannot open include file: "tmschema.h": No such file or directory (afxwin.h)
it returns in several cases
anyway can help?
thanks
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
YaronNir wrote: anyway can help?
Does tmschema.h exist?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
actually you are right, it doesn't
will check more
thanks
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
|
The include file "tmschema.h" is part of the Microsoft SDK (in v6.0 and v7.0), and is included by Visual Studio 2010 (in afxwin.h). However, Visual Studio 2012 doesn't appear to have the correct include files and/or libraries.
I'm looking to see if there's a known solution, and I'll post here again when I've worked it out!
|
|
|
|
|
hello guys... I have these two track bars on my form. Now even though I check which tracked bar was clicked; it still executes the code twice which is very awkward. Here is what I am trying
void CMainDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if((CSliderCtrl*)pScrollBar == &m_trackONE)
{
}
if((CSliderCtrl*)pScrollBar == &m_trackTWO)
{
}
}
It correctly recognizes which track bar I clicked but why does it starts executing all over again? thanks for any pointer.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
does nSBCode change between calls?
|
|
|
|
|
Thanks for ur time. It does change. For both track bars I checked this and both times
- on first call nSBCode had a value of 3
- on second call nSBCode had a value of 8
This world is going to explode due to international politics, SOON.
|
|
|
|