PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Compiler detecton
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Compiler detecton

Réponse
 
LinkBack Outils de la discussion
Vieux 08/02/2008, 21h50   #1
Max
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Compiler detecton

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?
  Réponse avec citation
Vieux 08/02/2008, 22h02   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

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?


Detect, no. The language does not mandate the compiler to identify
itself in any way. However, most compilers do offer a few predefined
macros that would you. For example, Visual C++ compiler has the
'MSVC_VER' macro that is defined to match the version of the compiler.
Other compilers do similar stuff, read about their "predefined macros"
in their documentation. IOW RTFM. :-)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  Réponse avec citation
Vieux 08/02/2008, 22h52   #3
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

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
  Réponse avec citation
Vieux 09/02/2008, 00h40   #4
Walter Bright
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

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
  Réponse avec citation
Vieux 09/02/2008, 18h52   #5
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

Max wrote:
> Is there a way to detect the compiler being used?


There's no *standard* way of detecting it. However, most compilers
will define some precompiler constant(s) to identify themselves. What
these constants are is completely up to the compilers. Also, there's no
guarantee that a newer version of the compiler will not change the name
of that constant. It's all up to the compiler developers. (Since the
standard doesn't specify anything about this, they are free to do as
they like.)

The documentation of some compilers might explicitly mention which
precompiler constants they define for all programs. With some compilers
you can actually print out all the precompiler constants (although
searching for an identifying constant will then be guesswork).
  Réponse avec citation
Vieux 09/02/2008, 19h12   #6
Andrey Tarasevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

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
  Réponse avec citation
Vieux 10/02/2008, 10h52   #7
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

On Feb 8, 10:50 pm, Max <maxh.is.h...@gmail.com> 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 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:james.kanze@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
  Réponse avec citation
Vieux 11/02/2008, 12h43   #8
Stefan Naewe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compiler detecton

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 s:

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h59.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17030 seconds with 16 queries