# Compile Errors != Linker Errors, BTW why do I get Linker errors?

#### Daniel Duffy

##### C++ author, trainer
Software Maintenance is not a top priority in CS education. This is what can happen when you jump head-first into a software project. Happens a lot.

“A Big Ball of Mud is a haphazardly structured, sprawling, sloppy, duct-tape-and-baling-wire, spaghetti-code jungle. These systems show unmistakable signs of unregulated growth, and repeated, expedient repair. Information is shared promiscuously among distant elements of the system, often to the point where nearly all the important information becomes global or duplicated. The overall structure of the system may never have been well defined. If it was, it may have eroded beyond recognition. Programmers with a shred of architectural sensibility shun these quagmires. Only those who are unconcerned about architecture, and, perhaps, are comfortable with the inertia of the day-to-day chore of patching the holes in these failing dikes, are content to work on such systems.”

#### Daniel Duffy

##### C++ author, trainer
How to avoid output disappearing in Visual Studio

1. Select project properties
3. Set property Subsystem to value /SUBSYSTEM:Console

4. Save

Arrivederci no system("pause")

#### Daniel Duffy

##### C++ author, trainer
Quiz: how to make loops but exclude one index. Which one do you prefer?

C++:
void TestLoops()
{
std::vector<double> v(20);
std::iota(std::begin(v), std::end(v), 0.0);

std::size_t i = 10;

// I, stops at i
for (std::size_t j = 0; j < v.size() && i != j; ++j)
{
std::cout << j << ",";
}
std::cout << '\n';

// II
std::cout << '\n';
for (std::size_t j = 0; j < v.size(); ++j)
{
if (j != i)
{
std::cout << j << ",";
}
}
std::cout << '\n';

// III
for (std::size_t j = 0; j < i; ++j)
{
std::cout << j << ",";
}
for (std::size_t j = i+1; j < v.size(); ++j)
{
std::cout << j << ",";
}

}

#### ExSan

##### Active Member
Quiz: how to make loops but exclude one index. Which one do you prefer?

C++:
void TestLoops()
{
std::vector<double> v(20);
std::iota(std::begin(v), std::end(v), 0.0);

std::size_t i = 10;

// I, stops at i
for (std::size_t j = 0; j < v.size() && i != j; ++j)
{
std::cout << j << ",";
}
std::cout << '\n';

// II
std::cout << '\n';
for (std::size_t j = 0; j < v.size(); ++j)
{
if (j != i)
{
std::cout << j << ",";
}
}
std::cout << '\n';

// III
for (std::size_t j = 0; j < i; ++j)
{
std::cout << j << ",";
}
for (std::size_t j = i+1; j < v.size(); ++j)
{
std::cout << j << ",";
}
}

Last edited:

#### Daniel Duffy

##### C++ author, trainer
A general remark that causes issues and leads to somewhat (and long) trial-and-error debugging sessions:
1. Distinguishing between compiler and linking errors; knowing what they are, what causes them and how to resolve them.
2. Seeing a compiler as a series of steps to translate Hello.cpp to Hello.exe
3. Really reading error messages and go to step 1.
4. When debugging, reduce the scope (e.g. 1st test w/o ExcelDriver). Solving 2 problems simultaneously is not a good idea.
5. Take an analytical approach.
In one of my early modules I explain the compilation process.

#### Daniel Duffy

##### C++ author, trainer
Quiz:
Doing a small least-squares linear regression and my first output was wrong. Sometimes it is due to lack of good code inspection and not the math which is impeccable Can you spot my stoopid mistake?

Code:
std::vector<double> MyGradient(const std::vector<double>& theta)
{ // Gradient function in ML minimax solvers

// line y = a + bx

std::vector<double> result(2); // dF/da, dF/db

double a = theta[0]; double b = theta[1];
double xj, fj;
double dfda = 0.0;
double dfdb = 0.0;

for (std::size_t j = 0; j < x.size(); ++j)
{
xj = x[j];
fj = y[j] - a - b * xj;

dfda += fj;
dfdb += xj * fj;
}

result[0] = -2.0*dfda;
result[0] = -2.0*dfdb;

return result;
}

Last edited:

#### Daniel Duffy

##### C++ author, trainer
The smart Q which Boost version with VS2017

#### Daniel Duffy

##### C++ author, trainer
Question:
Someone told me that Mac machines don't support VS2019 C++.

AFAIR it does. Has something changed?

#### APalley

##### Well-Known Member
Question:
Someone told me that Mac machines don't support VS2019 C++.

AFAIR it does. Has something changed?
At the moment, VS does not seem to offer C++ in its Mac version

#### Daniel Duffy

##### C++ author, trainer
Facebook and Microsoft join up with Visual Studio