Undefined references -Triangle Comparer

Pages: 12
@agent max

Understand that projects have multiple coders, those big projects might have 200 of them: 20 teams of 10. Namespaces allow variables/functions/classes with the same name to be hidden from other parts of the project. It all boils down to the concept of scope namespaces provide yet another way of providing a different scope, in turn this prevents clashes of names.

Also understand that libraries have their code in namespaces - look at the boost library. So if one wants to use anything in that library, one needs to deal with namespaces.

I understand that you are only writing small programs for school at the moment, but it is good practise to organise you code into namespaces, even if you never collaborate with anyone, it could save you from yourself when you write a program that is only a few KLOC.

agentmax wrote:
Holy mackerel! My computer would probably go splat on me if I tried to compile anything that took over a few minutes!


it wouldn't. have a go at compiling the latest version of gcc or clang - see how long it takes. Make sure to configure it, so that it only does C++ or just the languages that you want to use. Otherwise it will do all of them, and you will have Ada, Fortran, Go etc without realising it. With gcc there is an option to set the number of cores to use, that will speed things up a bit.
As to why using namespace std; can be a bad idea:
https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

It is not wrong to have using namespace std;, it can be more hassle than it's worth at times to save a couple of keystrokes. IMO. I refuse to use it. I don't even like having more direct using statements like using std::cout;, etc.

I am a language purist, I guess. My brain and fingers are coordinated and on auto-pilot for typing std::. YMMV.

But what would you use a namespace for, anyway?

https://www.learncpp.com/cpp-tutorial/2-9-naming-collisions-and-an-introduction-to-namespaces/

Learn C++ has other lessons on namespaces, look in the site index under "Namespace."
How on earth do I compile a compiler? I mean, it's all binary code. I know, I've looked at it. Here's a sample:
<BA>^R^@^@^@H<89><DF>L<89><F6>
<E8>j^@^@^@H<8B>^@<C7>x^@^@^@<BA>^R^@^@^@H<89>
<DF>L<89><F6><E8>P^@^@^@H<8B>^@<C7>@^L<FF><FF><FF>
<FF>L<8D>5<B0>-<8B>^C<BA>^X^@^@^@H<89><DF>L<89><F6>
<E8>/^@^@^@H<8B>^@<C7>x^@^@^@<BA>^X^@^@^@H<89>
<DF>L<89><F6><E8>^U^@^@^@H<8B>^@<C7>@^L<FF><FF><FF><FF>
[A^]<C3>f^O^_D^@^@UH<89><E5>AWAVAUATSH<83><EC>^XH<89>
<D3>I<89><F7>I<89><FE><E8>^A.<FF><FF>I<8B>^V<89><C1>L<8D>,
<CA>H<8B>^L<CA>H<85><C9>^O<85><95>^@^@^@L


Literally, that's what I get when I type less clang++ in the /usr/bin/ directory.

How would I go about compiling that???

Regarding namespaces, I see what you mean. I read the article you gave me earlier, and it opened my eyes. I did not realize you could do all that stuff with namespaces!
Last edited on
How am I supposed to compile that???

Hehe, you get the compiler's source code:
https://llvm.org/docs/GettingStarted.html
Although this is for LLVM's clang, upstream of yours.

It's "upstream" because Apple clang is a derivative of this project. As features are implemented in LLVM's Clang, they "flow downstream" to Apple, who implements them in their derivative compiler.
Last edited on
closed account (z05DSL3A)
How on earth do I compile a compiler?
It's like any program, you write you code and compile it, it is just the end result is a compiler. It was obviously a bit more tricky way back when the dinosaur book roamed the earth.
How on earth do I compile a compiler?

We are all lucky, there are compilers already available that can take source code, source code for compilers for example, and produce machine code that works on the target OS.

The first compiler had to be hand-coded in machine code. Now THAT is old-school computing!

We can thank Admiral Grace Hopper for compilers.
https://history-computer.com/grace-hopper-history-of-the-first-compiler-a-0-system/
Last edited on
We can thank Admiral Grace Hopper for compilers.


... and also curse her for Cobol - my most hated language. We had to do a 'proper' banking project in Cobol whilst I was at university - using batch processing and punched cards. Talk about feeling suicidal...... I vowed never, ever, ever again to use Cobol.

The first compiler had to be hand-coded in machine code. Now THAT is old-school computing!


As part of our os/compiler course at university, we had to write, in machine code, an assembler for a mythical computer (all we had was the 'interpreter' for this machine code). We then had to code the assembler in the assembler language so that it would process itself. We than had to code a compiler in Pascal for 'small pascal' that produced as output assembler that would be processed by our assembler. And then write the 'small pascal' compiler in 'small pascal'. We ended up with a 'small pascal' compiler written in itself, producing our assembler code which was assembled using our assembler written in itself which produced the machine code processed by the interpreter. If we wanted a debugger, we had to write one! Now that was a project! Ah those were the days.....
@mbozzi,
Yes, I know how to find the source code for it, but it's all in binary and I have no idea how to translate it.

@Furry Guy,
Do you know if there is a compiler that will compile binary code? Like the sample I posted earlier?

@seeplus,
Wow, batch processing and punch cards with COBOL? That had to have sucked! And you had to actually make a compiler?? That must have been hard!
it's all in binary and I have no idea how to translate it

Nah, it's in C++ (mostly). Here's part of it:
https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp#L348
Last edited on
Well when I go to the /Library/Developer/CommandLineTools/usr/bin directory, which is where clang++ is installed, and I enter less clang++, (and less is a command to spit the contents of a file onto the screen), I get stuff that looks like this:
<CF><FA><ED><FE>^G^@^@^A^C^@^@<80>^B^@^@^@^T^@^@^@^@^@<85>
<80>!^@^@^@^@^@^Y^@^@^@H^@^@^@__PAGEZERO^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
@^@^@^@^@^@^@^Y^@^@^@<C8>^B^@^@__TEXT^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@
^@^@^@<A0><93>^C^@^@^@^@^@^@^@^@^@^@^@^@^@<A0>
<93>^C^@^@^@^@^G^@^@^@^E^@^@^@^H^@^@^@^@^@^@^@__text^@^@^@^@^@^@^@^@^@
^@__TEXT^@^@^@^@^@^@^@^@^@^@<80>'^@^@^A^@^@^@<B8>


That was just the first 5 lines or so. There's more. Whole scads of stuff that's mostly @^ with other stuff like <FF>A<B8>^A^ mixed in.

That clang driver on GitHub was definitely not binary, I wonder if the clang++ that I'm seeing is the exec? Because that would explain why it's all in binary.
That clang driver on GitHub was definitely not binary, I wonder if the clang++ that I'm seeing is the exec? Because that would explain why it's all in binary.


Yes, that's the executable. In a format called Mach-O (probably), since you're on an Apple system.
https://en.wikipedia.org/wiki/Mach-O
I know very little in general about Apple's systems, so take what I say with a grain of salt. I have no desire to support such a platform.

The command file "$(which clang++)" would tell you more specifics
Last edited on
Ah, I see. Thanks!

Hehe, that's funny, because I could say the same about Windows. (No offense). But I have used VS and I don't like it very much–just too complicated (says me while I try to figure out how to use a Bash command line ;).

Hmm. When I type "which clang++" I just get the directory in which the executable is stored: "/usr/bin/clang++".
Right now I'm using Windows primarily but I programmed in a Linux environment for years prior, that's my preference. I write all my code using Emacs. VS is installed but I don't use it that often.

Hmm. When I type "which clang++" I just get the directory in which the executable is stored: "/usr/bin/clang++".

If the command
which clang++
outputs
/usr/bin/clang++
Then the command
file "$(which clang++)"
Runs the command
file "/usr/bin/clang++"
This is called command substitution
https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html
Last edited on
Oh! I thought you just meant "which clang++". Ok, I'll try it. And I believe the Terminal application has emacs, but I've never used it.

Ok...the command substitution thing gives me
/usr/bin/clang++: Mach-O 64-bit executable x86_64


64 bits??? That's like 8 integers in C++!! Is something wrong there?
Topic archived. No new replies allowed.
Pages: 12