473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Compiler detecton

Max
Is there a way to detect the compiler being used? Namely, is there a
way to have lines of code that are included or ignored by specific
compilers. Or, better, finding certain compiler behaviors to use/
avoid. For example, Visual Studio automatically inserts a
system("PAUSE") statement. Is there any way to detect that VS is being
used and not compile the equivalent line in my program?
Feb 8 '08 #1
5 1412
On 2008-02-08 22:50, Max wrote:
For example, Visual Studio automatically inserts a system("PAUSE")
statement. Is there any way to detect that VS is being used and not
compile the equivalent line in my program?
Is that something they have started doing recently, because that has
never happened for me.

Or, less sarcastic: No, VS does not insert anything in your code, but if
you use Ctrl+F5 to run your program from the IDE it will be started
using a batch-file which waits for input before terminating after your
program has returned. If you do not want that you can use just F5 to
start the program.

--
Erik Wikström
Feb 8 '08 #2
Max wrote:
Is there a way to detect the compiler being used? Namely, is there a
way to have lines of code that are included or ignored by specific
compilers. Or, better, finding certain compiler behaviors to use/
avoid. For example, Visual Studio automatically inserts a
system("PAUSE") statement. Is there any way to detect that VS is being
used and not compile the equivalent line in my program?
With the Digital Mars C++ compiler,

#if __DMC___
.... insert Digital Mars C++ specific code here ...
#endif

works.

----------------
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
Feb 9 '08 #3
Max wrote:
Is there a way to detect the compiler being used? Namely, is there a
way to have lines of code that are included or ignored by specific
compilers. Or, better, finding certain compiler behaviors to use/
avoid. For example, Visual Studio automatically inserts a
system("PAUSE") statement. Is there any way to detect that VS is being
used and not compile the equivalent line in my program?
As others said, use compiler-specific macros. It is '_MSC_VER' for VC.

You can "reverse-engineer" a list of specific macros for different compilers
from this header file (Trolltech)

http://web.mit.edu/qt_v3.3.3/www/qglobal-h.html

Scroll down to the list of compilers (line 183).

(I couldn't find a nicer list right away, although I'm sure I've seen it somewhere.)

--
Best regards,
Andrey Tarasevich
Feb 9 '08 #4
On Feb 8, 10:50 pm, Max <maxh.is.h...@gmail.comwrote:
Is there a way to detect the compiler being used? Namely, is
there a way to have lines of code that are included or ignored
by specific compilers. Or, better, finding certain compiler
behaviors to use/ avoid. For example, Visual Studio
automatically inserts a system("PAUSE") statement. Is there
any way to detect that VS is being used and not compile the
equivalent line in my program?
As others have pointed out, almost every compiler pre-defines
some preprocessor symbols to identify itself, hoping that they
won't conflict with those of any other compiler. But a more
pertinant question, in my mind, would be why you would want to
depend on this. First, of course, most code (99% or more)
should be written so that it doesn't matter. And for that that
does, the symbols are generally defined in a way that only
allows you to use #ifdef, which of course makes the code rapidly
unreadable and unmaintainable. What you really want is 1) one
common symbol which will resolve to the name of a directory, so
you can build up includes to get the right headers *and* system
dependent code, and possibly 2) common symbols which define the
presence or absense of specific features, or how they work (e.g.
things like GB_allowedDirectorySeparators, which can be either
"/" or "\\/"---or maybe something completely different on a
platform I don't currently target). In my experience, the best
way to handle the first is in the command line in the make
file---that needs to be adopted to each compiler anyway, and
adding something like /Dsyst=windows to it doesn't really cause
any additional problems. Or---what I actually use---you can add
a /I option with the directory where you put the system specific
headers. And the second is easily handled once you've done
this; you pick up the defined from a system dependent header.

As for a tool which automatically inserts code which you don't
want, the simple answer is: don't use it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 10 '08 #5
On 2/8/2008 10:50 PM, Max wrote:
Is there a way to detect the compiler being used? Namely, is there a
way to have lines of code that are included or ignored by specific
compilers. Or, better, finding certain compiler behaviors to use/
avoid. For example, Visual Studio automatically inserts a
system("PAUSE") statement. Is there any way to detect that VS is being
used and not compile the equivalent line in my program?
Maybe this helps:

http://predef.sourceforge.net/

Regards,
Stefan
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Feb 11 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.