Re: show disassembly
"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.
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.
[...] 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.
here is the code:
This code is wrong on so many levels. Read on.
-----------------------------------------------------------------------------------------
#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.
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.
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.
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. 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
HTH
Alex