C++ with 2 compilers [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a project which I would like to code on both an Ubuntu and a Windows machine. On Ubuntu I'm using gcc, and on windows I would like to use MSVC.
Is it a good idea to compile the same code with 2 different compilers like this? Or would I run into issues down the road?
Thanks.

It is an excellent idea. In the past, I've found a bunch of bugs in my code that I could only see after switching compilers.

If you want to compile for different platforms, you have to compile with different compilers (even if they are different versions of the same compiler).
If you compile with both GCC and MSVC, you will find you can't use a lot of the extensions that each compiler provides. You will also find annoyances like MSVC puts an underscore on the front of functions like _open. Basically, this comes down to "welcome to the wonderful world of portable coding".
On the other hand, once you start writing code for two compilers, it becomes much easier to add a third - and I would recommend adding Clang to the mix as a cheap and cheerful static analysis tool.

Microsoft is making it easy, by allowing you compile code directly from Visual Studio on a Linux box. It's pretty cool.
https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

Related

Prettify compiling C++ from Command Line [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm playing with compiling C++ from native Windows CMD via VS 2017 compiler (vsvarsall.bat setup).
Is there any way to reduce the output of cl command, like Microsoft rigths for compiler and linker?
Also, offtop question: is it possible to compile code with UNICODE or ANSI strings (like I'm able to build from Visual Studio IDE), or am I gotta use manual #defines?
For your first question, see the /nologo compiler flag.
I'd guess the second is why people are voting to close--there's quite a variety of ways to deal with ANSI/Unicode strings, and without quite a bit more definition of what you really want, chances are pretty poor that anybody can give a meaningful answer.

Different compilers, different syntax [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to compensate the differences between the syntax of different compilers of the same programming language? How could I know which one is standard and used worldwide to make projects?
For example: I worked 4 months on Borland C++ compiler to learn C++ but now I saw the syntax of Borland, Visual C++ and Developer C++ is different. I am confused, need some guidance...
The first solution is to not use parts which are specific to one compiler or another. Before you use a feature of the language, check on the internet to see if it's specific to any one compiler. If it is, then don't use it.
Other than that, actually making a C/C++ program which is compilable by different compilers is a task which takes effort. It doesn't "just happen", because the compilers each have their own quirks, their own level of support of the standard etc. Even writing compliant C99/C++11 code you might still see issues. So one solution is to actually compile the program with different compilers on a regular basis (say, as part of testing before pushing code to the central repository) and make sure that all of them can compile the code, and the resulting software can run.
As for "standard" compilers, on Linux and Mac gcc and clang can be considered "gold". On Windows, the compilers by Microsoft are standard.

Compiling C++ code (BASIC Interpreter) into ARM assembly [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm writing a basic command line operating system for the raspberry pi, much like those on computers from the 70's and early 80's. I have made the basic text input / output with assembly and would like to incorporate a BASIC interpreter into my code. I was thinking of writing my own version of BASIC and an interpreter in C++/Java (maybe not, since it's compiled into bytecode) then compiling it into ARM assembly for the raspberry pi, is this possible?
P.S I considered writing it in assembly, but figured that would be too complicated for my abilities.
Yes, it's possible since once you have a C++ compiler for your taget platform. You can use any language you want/need to, including Java since once all needed tools to compile/interpret are available in the target platform. You can do in assembly too. But do you really need/want to? it's really a lot of job without no much fun.

At the current stage, why most of the modern C++ compilers only support limited C++0x features, while Clang/GCC supports all of them? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am new to C++11, and found it is a difficult and tedious work to find alternative ways to make my code compatible with both Clang and Visual C++.
What's the reason behind this fact? Is that technique difficulties? Compatibility with old non-standard language extensions? Different priorities? Or any other possibilities?
The reference page: https://wiki.apache.org/stdcxx/C++0xCompilerSupport
Why most of the modern C++ compilers only support limited C++0x features, while Clang supports all of them?
clang was designed much later than most of the other major compilers, and was built in a way that makes it easier to support some of the modern features. Many other compilers, such as MSVC and GCC, support many other targets than clang, and have a large legacy code base. Changes to these compilers tends to come more slowly over time.
and found it is a difficult and tedious work to find alternative ways to make my code compatible with both Clang and Visual C++.
In general, I've found that if you stick to the subset (in this case, write for Visual C++), then clang will typically support the code with no changes, provided you avoid the Microsoft language extensions. Moving the other direction is often more challenging.
Because the changes on Visual seems to take time, like in GCC. GCC almost support everything.
But also it is a question of priority. In fact GCC was full C++11 complete before CLang oficially (even if this was just because CLang was waiting for the official release date with everything ready).
Visual takes more time because they also spend energy in making the IDE better. And they have less developers.

understanding c++, compilation etc [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Do you know a good, concise (not a book, possibly free documentation) reference that explains the basics of how a c++ compiler works? I think it'd be beneficial for better understanding some rules of c++ programming.
GCC Internals free ebook.
The purpose of this book is to address
the demands of GCC hackers. We start
with a description of GCC 3.4.1
architecture focusing on the source
code parser. We chose this version of
GCC because we used this version
mostly. Then we address the problem of
extension development. We present the
GCC Extensibility Modules (GEM)
project in the next chapter. GEM
provides a number of hooks throughout
GCC source code. It is implemented as
a patch to GCC. A GEM-based compiler
extension is developed as a
stand-alone program. When the
extension is completed, only its
source code is distributed compared
with distributing the source code of
the GCC if GEM is not used. We give
examples that demonstrate GEM
programming at the end of the book.
(EDIT: Sorry, I missed you don't want a book. But I still think this is great resource of information you are looking for. You certainly don't need to read it as a whole, you can go only through the sections you are interested in.)
I found this university site which explains the steps of the compilation process. It covers how to compile your code into an executable, a shared library, or a dynamically linked library using GCC. It also covers how the compiler knows where to look for header files and libraries, and other topics.