Will C++ code be compiled differently on different computers?

Pages: 12
Thanks JLBorges, those are two things I never even thought about!

How long would you say it would take to compile a game that would, say, have a size of 200MB after compiling?

How about, we give the user a fully built executable, but also, while he is playing the game, in the background, the executable is also compiling the same game in bits to a different location? And finally when all bits are compiled, they are linked and this new executable file replaces the old one. And everything not required like the compiler itself is deleted.

Would that be useful?
Is it worth sacrificing the user's resources to compile 200MB?

If at all there is any improvement at all, then heck I say that it's kinda worth it, if the user agrees for it.

This could be helpful for big games where performance is very crucial. So would they do something like this?


Can the user unpack the executable and view the source code? In that case, what do I do to preserve the source code? (say that the source code is important because the application is a multiplayer-online game, then we don't want the user to read the source code)
Last edited on
How long would you say it would take to compile a game that would, say, have a size of 200MB after compiling?


A size of executable doesn't say much about how much source code there is. I could compile 2,000 LOC and have an executable that is 100K. Larger programs have many library files (dll files on windows) dll stands for dynamic link library, machine code in these files is executed as required to reduce RAM usage while the program is running.

To give you an idea, I sometimes get the latest code for g++ and compile it, it usually takes about 1 hour for just C & C++, more like 4 hours if I were to select other languages that gcc can do. But there are larger applications than that.

How about, we give the user a fully built executable, but also, while he is playing the game, in the background, the executable is also compiling the same game in bits to a different location? And finally when all bits are compiled, they are linked and this new executable file replaces the old one. And everything not required like the compiler itself is deleted.

Would that be useful?


No that seems silly in my view, either provide the latest version of a binary, or let them build, no sense in doing both at the same time.

But it kind of sounds like you mean a patch file. These could be made up of the dll (library) files and other resources that have changed, along with an installation script that may be as simple as copying the files into the correct location. The number of these files could be quite small, no need to spend long hours re compiling the entire application.


Can the user unpack the executable and view the source code? In that case, what do I do to preserve the source code? (say that the source code is important because the application is a multiplayer-online game, then we don't want the user to read the source code)



Perhaps best if you read up about rpm which is the Redhat Package Manager as an example of what happens when building from source. One doesn't unpack the executable, they unpack the tar file, which is conceptually like a zip file.
Would that be useful?
What if when coming out of your house you walked backwards while wearing a hat over your face. Would that be useful?
If you're asking if something would be useful just in a general sense then you're not thinking about solutions to a problem, you're thinking about random things and seeing if you can find a problem that they can solve. That's a great way to do really bad engineering.
Instead, consider:
* What's the problem in front of me?
* What tools do I have available? How can I combine them?
* Does a particular combination actually address the problem? How thoroughly? Am I leaving any aspects of the problem unaddressed?
* How do the various solutions I found compare? What are each of their benefits and drawbacks (relative and absolute)?
* Has anyone solved this problem or a similar one before?
* How did they do it? Why?
* Is their solution applicable to my problem? How does it compare to the solutions I found?
to echo that, go play a game :)
seriously.

what happens when a game has a minor patch? Some games can even do this while you are playing; they download and the new version and the old code is still 'live' in memory until you restart. Other games knock you out and make you restart. You need a way to force the players to update in case you had to patch an exploit that was causing serious problems (google "caturday NWNO" for an example).

How much do they download, and what is it? It tells you in many games, and most of the time its a couple of library files, not gigabytes of junk.

major patches --- new content, graphics re-do, expansions, etc sometimes download everything (or nearly) again. But the bulk of your updates are so small they take just a couple of seconds to download and its done because its delegated to many library files instead of one monolithic monster executable.


your typical user wants to start a program and at the very worst case scenario, it spends less than 60 seconds patching, closing itself, restarting, and putting you back in business. Best case, they can't even tell it happened.
Last edited on
@Grime

Just wanted to comment on your posts in general:

Instead of asking questions about your wacky solutions to things you don't understand, why don't you do your own research about how various things do work? Have you heard of Google and Wiki and Stack Overflow? We would rather answer questions about specific things you couldn't quite understand after demonstrating some research.

At the moment, all these questions could be considered a form of trolling aimed at time wasting. If that is not what you are about, then consider asking some decent questions.

Things like: "Can the user unpack the executable and view the source code?" Maybe you are confused with a Winzip exe file or an installation exe, but either way, it demonstrates that you are getting way ahead of yourself.

In your learning, things need to be done in order. Before learning all about package management and installation and patching, first learn in detail about compilers and what it means to compile and link an application.

Perhaps you could spend more time writing your own code, rather than getting concerned with what happens on large systems?
In your learning, things need to be done in order. Before learning all about package management and installation and patching, first learn in detail about compilers and what it means to compile and link an application.


@TheIdeasMan, maybe you can give me a suggestion by giving me a starting point? How about that ;)

Perhaps you could spend more time writing your own code, rather than getting concerned with what happens on large systems?


Can I not aspire to understand how 'large systems' work then? What if I were to want to write my own application for once? And what if I want to learn how other people write their applications?

The first time you ever wrote a letter say, did you write it on your own without ever having read a letter before? Are you telling that you were not slightly influenced by what letters you had read before?

Don't get me wrong.. this is not hate speech.. I don't know when something classifies as being rude but I'm not trying to be rude.. I look up veterans like you! ;)
Seriously though I appreciate any book suggestions.. about computers/how they work. Or about software and how they work.. Just not a boring textbook.
Can I not aspire to understand how 'large systems' work then?
You can, once you've designed some medium-sized systems and understood the challenges involved.
Just not a boring textbook.
... Its a dry subject. You are not going to get a pop-up book or anything here, you are going to get a reference book of one flavor or another which is what text-books are, really (classrooms treat them differently but they are organized in a way to flip to a subject and study that section for a reason).

One of the best things you can do to understand how a computer and operating system work is to take a class in assembly language.

Its an admirable goal to want to know as much as you can, but you have to understand just how BIG that is. In 1985 you could understand just about everything about the hardware, operating system, software, and more about your system. Today, you have to accept that you will use libraries that you have no clue how they really work, or tools that do things for you that would take years to re-create by hand. One of those is deployment management tools --- there are teams that build those tools, but to do it from scratch is challenging to deploy a professional package. I mean, I can zip up a couple of dlls and my executable and email it to my co-worker all day long, and some portable programs or small freeware is still deployed this way, but you cross a threshold at some point where you need a better solution. When you reach that point, you can either take a couple years off to recreate what you need or use what someone else has done. Modern software development is very heavily tied into just plugging existing tools together in new ways. Only a very small number of people are working on the next graphics engine; everyone else is just using their library(s).

I don't say this to discourage you, but to scope the problem. To understand everything about everything in our world is multiple lifetimes worth of work.


Grime wrote:
@TheIdeasMan, maybe you can give me a suggestion by giving me a starting point? How about that ;)


TheIdeasMan wrote:
Have you heard of Google and Wiki and Stack Overflow?


There is a tremendous amount you could learn from those sites, if only you would search first and ask questions later.

I am not trying to discourage you either, It's just you are getting way ahead of yourself and asking silly questions, IMO.

It's like someone who is 18 yo, just started University, wants to be the Vice Chancellor, and guessing what it is they actually do.

Edit:

Perhaps start with learning about compiling, linking, what assembly is, and optimization.

godbolt is an online compiler that lets one look at the assembly. Try some simple program in C or C++, look at the assembly, un-optimized and optimized.
Last edited on
@TheIdeasMan

You tell me what I should be googling or searching.
Searching for "How does a compiler work" won't give me any information that I don't already know.

Googling or searching for any such term will only give 'brief' explanations. Which I already know.
You tell me what I should be googling or searching.


How about :

wiki compiler
wiki linker
wiki assembly

How difficult was that?

Googling or searching for any such term will only give 'brief' explanations. Which I already know.


If you knew what an executable is, you wouldn't have asked : "Can the user unpack the executable and view the source code?"

Can you tell us simply what the relationship between assembly and an executable is ?

You could learn more about C++, I bet you don't know everything about that.
Okay what's next? What's after reading the wikipages?

I'm sure everybody here knows how to mock. Maybe you can make a difference by telling me what to do after reading those wikipages, asides from telling me to read the language itself. And since I have mentioned it, you should not say "read the C++ language" on your next post but something tells me that you will anyway. So assume that I have perfected the C++ language. Now tell me what's next.
Last edited on
Okay what's next?


Learn to ask some proper questions.

That's all from me.
But what's after wikipages.. and I'm not trying to be rude I respect you a lot TheIdeasMan. I admire people like you who take the time to be part of forums like these even though you are probably a professional programmer and are very busy.

You software engineers learn everything you need in your courses. But what about people who don't take software as their profession? Is wikipages all we can have?

I want to do stuff that you people do. Maybe I know nothing about computers but maybe at the same time I want to know. But wikipages won't tell me half the story you people know about.

I sincerely want to know. I tried googling for books but I never know what's right or what's not even required and that's why I ask you people.

We learn C++ in school but it's very basic. Till now we have only touched on structures and functions. And because I study in a backwards syllabus I have to use Turbo C in school. And our textbooks are backwards as well. I don't know whether I want to take software professionally because I have other aspirations in my life. But I also want to do programming at the same time.

I might not become an engineer but I want to do programming as a hobby. I know it's weird but that's just how I feel and it's not something I can back.

Maybe because of the path I'm choosing I will never be able to write and distribute a complete program. That's okay but I at least want the thought that I am able to. I don't want this small detail to change what I want to do in life.

So I'm sorry that I asked stupid questions. But I hope the question I am asking now - that of guidance - is not equally stupid.

And sorry if I was rude to you TheIdeasMan.
Last edited on
Googling or searching for any such term will only give 'brief' explanations. Which I already know.

In my opinion, it is normal to feel stuck where
a.) "advanced" topics assume too much prior knowledge
b.) "beginner" topics assume too little
Because this is where that the learning-curve starts to flatten. You are not short on things to learn, nor resources to learn from.

Like you, I am a self-taught programmer. For me, the hardest part of self-teaching is maintaining the physical and mental health required - the self-discipline - to sit down and actually study from a proper resource. Hand-holding tutorials stop being useful after a while.

If you just want someone to make sense of all the info and help you pick a C++ book, I'll do it. Get this one:
Stroustrup: "Programming: Principles and Practice using C++ (Second Edition)" Addison-Wesley 2014, ISBN 978-0-321-99278-9.
You can maybe take the ISBN number to your public library. If you'd rather buy it, assuming you live in the west, you can get a paper copy for probably USD$30. Stroustrup is the original designer of C++, and his books are well-regarded.

If you don't want to buy a textbook, that's okay: you're on a computer, so practice. After all, the materials are cheap.

If your interests are in compilers, consider writing a compiler. If that seems too difficult, aim for an interpreter instead, selecting a simple source language, like a simple Forth or a Lisp. If that still seems too challenging, an expression calculator with parentheses and stuff is very similar, and can be implemented using Dijkstra's shunting-yard algorithm. (It's not trivial, by any means, but achievable - and in fact this is where I suggest you start.)

If you don't want to write a "real" program by yourself, use someone else's. Go find something you're interested in, head over to GitHub or whatever, find an open ticket on some project and work on that. It is really that simple, and you don't need to be an expert - most programmers will be excited to see some interest in their work.
Thanks mbozzi I guess I'll read a proper C++ book for starters and who knows the possibilities are endless!

Still though do any C++ books talk about how to compile applications with resources and etc?
Learning by doing is the best way to go. Books and tutorials might or might not help.

What you need is some patience. Start small and grow. Do not try something that is over your head. It will cause more frustration than it helps.
Searching for "How does a compiler work" won't give me any information that I don't already know.
If this is what you want to know, the best place to start is the Dragon Book.
https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811/ref=sr_1_2?ie=UTF8&qid=1547042088&sr=8-2

Or maybe you want to ask "how does an operating system work?"
https://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/013359162X/ref=sr_1_1?ie=UTF8&qid=1547042192&sr=8-1

Or, "how does a computer work?"
https://www.amazon.com/Structured-Computer-Organization-Andrew-Tanenbaum/dp/0132916525/ref=sr_1_3?ie=UTF8&qid=1547042192&sr=8-3

(Needless to say, these all fairly advanced topics.)

There's no shortage of information available, if you'll just look for it.
Last edited on
Still though do any C++ books talk about how to compile applications with resources and etc?

I don't know. You might be better off looking in a Windows book for that. ("Resource files" and things are primarily a Windows concept.)

I'm unfamiliar with it, but people like to recommend Charles Petzold's books. The fifth edition of Programming Windows ISBN 1-57231-995-X has been highly recommended, and I imagine it covers this, although I can't say for sure. However, the impression I get today is that if you want to develop Windows programs the first choice should be C#, not C or C++.

IMO, the "hello world" of Windows resource files is to load an icon from one. I think Visual Studio has what you need built in (it used to).
Last edited on
Registered users can post here. Sign in or register to post.
Pages: 12