Re: show disassembly
"Alex Blekhman" wrote:
"Fil" wrote:
I solved the problem by neutralizing some functions I wasn't
using but that I had in other c++ files, thanks to comments, and
the problem disappeared in the main function.
Why do you think it's a problem? It's perfectly normal behaviour
of the debugger. If you don't have the source code for a function,
then debugger offers you the second best it can: disassembly
window.
You didn't say which version of VC++ you're using. If it's the
Express Edition, then you don't have source files for CRT
functions.
Yes, I am using the express Edition, I guess that's why.
I now have to problems:
- when I pass an array to a function it looks like the function
doesn't know the size of my array but just nows the first
element. I can also pass the side as a second parameter but I
guess we can do better.
No, you cannot. This is how things work. Array of T decays to T*
when array name is passed to a function. You must pass array size
as an additional parameter. If you don't want to use raw arrays,
then there is `std::vector', which can be queried of its size.
Cool, I am glad to know I am doing right here. I keep note of the vector
thing for later, when I am more confident with the classes.
[...] when I F11 my code and I arrive to the pow statement the
compiler asks me for an asm file and if I don't give him any he
starts going in the deassembly ://)
It means you don't have a source file for `pow' function.
I then would like to be able to get out of the disassembly window as soon as
the pow statement as been executed to keep on looking at my code with the
next c++ line. Is there something like VBE Ctrl+Shift+F8 to run in once the
content of the pow function?
here is the code:
This code is wrong on so many levels. Read on.
Thanks for the corrections. I am pretty proud to have something that sorts
well my array though, since I started coding a week ago.
-----------------------------------------------------------------------------------------
#include <iostream>
#include <math.h>
using namespace std;
int * sortArray(int iArray[],int arraySize);
void main(void)
{
int myArray[7]={6,3,5,7,1,2,4};
int sizeOfArray;
sizeOfArray=sizeof(myArray)/sizeof(int);
int * mySortedArray;
mySortedArray=new int [sizeOfArray];
mySortedArray=sortArray(myArray,sizeOfArray);
The memory allocated for `mySortedArray' is leaked. A value you
return from `sortArray' function overwrites the one stored in
`mySortedArray'. So, the pointer is lost forever and memory is
leaked.
I thought I had to keep some space in the memory to store the result of the
function. Should I just write this:
int * mySortedArray;
mySortedArray=sortArray(myArray,sizeOfArray);
int * sortArray(int iArray[],int arraySize)
{
//int arraySize;
int lMin;
int intMax;
int minIndex;
//arraySize=sizeof(iArray)/sizeof(int);
int * iResult;
Declaring all variables in the beginning of a function considered
bad C-style, which is better to avoid in C++. Declare variables as
close to their usage as possible.
That's cool because it will be easier to read, I was doing it because I had
been told it was good style.
iResult=new int[arraySize];
You don't need to allocate new array. `iArray' is an alias to
`myArray' outside of the function. Any change made within
`sortArray' is reflected in `myArray', as well.
But I am allocating for iResult, not for iArray. Shouldn't I?
I think I have to study the allocation because it's not clear to me when to
use it or not.
intMax=pow(2.,double(8*sizeof(int)))/2-1;//2147483647;
If you want to know max integer value, then include <limits.h> and
use `INT_MAX' predefined constant.
Good to know.
However, you don't need to know
max integer value. Here's the example of the simplest sort
algorithm:
"Bubble Sort"
http://www.paked.net/subject_pages/computer_science/prog2.htm
I am convinced most of the things I am coding already exist and have been
optimized through the years. I like to try to code them by myself for
exercise.
But I surely will use the optimized version if I need to include the
function in a project.
Thanks for the link.
HTH
Alex