Strange behavior in XCode, not exhibited in Dev-C++
Strange behavior in XCode, not exhibited in Dev-C++
- Subject: Strange behavior in XCode, not exhibited in Dev-C++
- From: Richard Rehl <email@hidden>
- Date: Thu, 8 Feb 2007 17:33:14 -0500
I'm having issues with the simple inclusion/exclusion of a single
#include <iostream> statement
in a source file which is strictly dedicated to defining two
functions for calculating the column widths of a series of integers
and their squares. If the statement is excluded, the calculation of
the width of the integers column is incorrect; when it's included,
the calculation is correct.
There should be absolutely no reason to include the statement in this
file as all output statements are handled from the main function.
As you can guess, I'm not very experienced at this. I've had to get
a POS PC for some coursework that I'm taking, so tried to compile the
same project in Dev-C++. The above behavior is not exhibited in that
environment, so I'm mystified. If anyone's interested, here's the code:
main.cpp
#include <iostream>
#include <cmath>
#include <iomanip>
#include "FindColWidths.h"
using std::endl;
using std::cout;
using std::pow;
using std::fabs;
using std::setw;
using std::setprecision;
using std::streamsize;
int main () {
double start = -10;
double end = 1001;
double absoluteLargest = fabs(start) < fabs(end) ? end : start;
cout << "Absolute Largest: " << absoluteLargest << endl;
int rootWidth = findRootWidth(absoluteLargest, 1);
cout << "RootWidth: " << rootWidth << endl;
int sqrWidth = findSqrWidth(absoluteLargest, 1);
streamsize prec = cout.precision();
cout << setprecision(sqrWidth);
for (start; start < end; start++) {
cout << setw(rootWidth) << start
<< setw(sqrWidth) << pow(start, 2)
<< endl;
}
cout.precision(prec);
return 0;
}
FindColWidths.cpp:
#include "FindColWidths.h"
#include <cmath>
//#include <iostream> //........................Here is the line in
question...........................
using std::fabs;
using std::pow;
int findRootWidth(double i, double width) {
if (fabs(i) < pow(10, width)) {
return int(width) + 2;
}
else {
return findRootWidth(i, width + 1);
}
}
int findSqrWidth(double i, double width){
if (pow(i, 2) < pow(10, width)) {
return int(width) + 1;
}
else {
return findSqrWidth(i, width + 1);
}
}
FindColWidths.h:
#ifndef GUARD_FindColWidths_h
#define GUARD_FindColWidths_h
int findRootWidth(double, double);
int findSqrWidth(double, double);
#endif
Sample output logs: With #include <iostream> enabled:
Absolute Largest: 1001
RootWidth: 6
-10 100
-9 81
With #include <iostream> disabled:
Absolute Largest: 1001
RootWidth: 3
-10 100
-9 81
TIA
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden