[c] ifdef keuze tussen 2 #includes

Pagina: 1
Acties:
  • 127 views sinds 30-01-2008
  • Reageer

  • Daniel304
  • Registratie: December 2000
  • Laatst online: 14-08 14:02
ik schrijf een programma en moet een keuze laten maken tussen 2 header files om compatibility tussen win32 en unix te garanderen...
ik moet het programma laten kiezen tussen
#include <conio.h>
en
#include "unixhead.h"

weet iemand hoe je dat netjes kan doen ?!?

  • whoami
  • Registratie: December 2000
  • Laatst online: 21:11
iets in die aard:
code:
1
2
3
4
5
6
#ifdef DOS
  #include <conio.h>
#endif
#ifdef LINUX
  #include <linux.h>
#endif

Even de sectie van de preprocessor statementes opzoeken in uw help.

https://fgheysels.github.io/


  • -FoX-
  • Registratie: Januari 2002
  • Niet online

-FoX-

Carpe Diem!

Kan je ze niet gewoon allebei includen ?
Maakt toch niet zoveel uit geloof ik.. :?

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 06-09 14:04

Creepy

Tactical Espionage Splatterer

Op woensdag 05 juni 2002 12:35 schreef -FoX- het volgende:
Kan je ze niet gewoon allebei includen ?
Maakt toch niet zoveel uit geloof ik.. :?
conio bestaat onder Linux niet, dus dat maakt wel degelijk uit.

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


  • Daniel304
  • Registratie: December 2000
  • Laatst online: 14-08 14:02
deze werkt dus ook ?!?
code:
1
2
3
4
5
#ifdef sun
    #include "standard.h"
#else
    #include <conio.h>
#endif

  • Soultaker
  • Registratie: September 2000
  • Laatst online: 06-09 19:42
Het gaat er dus om, om uit te zoeken welke preprocesser definities er onder welk platform geladen worden. In een standaard project van Microsoft Visual C++ wordt netjes WIN32 (en _WINDOWS) gedefinieerd.

In het geval van gcc kun je met 'cpp -dM' zien welke precompiler directives gedefinieerd zijn. Op mijn systeem onder andere unix, __ELF__, __unix__, __unix en __FreeBSD__.

Voor andere compilers of platforms moet je zelf even zoeken in documentatie. Hiermee zou je er toch wel uit moeten kunnen komen.

Trouwens:
Op woensdag 05 juni 2002 12:53 schreef Daniel304 het volgende:
code:
1
2
3
4
5
#ifdef sun
    #include "standard.h"
#else
    #include <conio.h>
#endif
Dit werkt niet. De hekjes moeten altijd het eerste karakter op de regel zijn om herkend te worden door de precompiler. Dit kan wel:
code:
1
2
3
4
5
#ifdef WIN32
#    include <conio.h>
#else
#    include "standard.h"
#endif

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 03-09 13:30

.oisyn

Moderator Devschuur®

Demotivational Speaker

Op woensdag 05 juni 2002 13:13 schreef Soultaker het volgende:
Dit werkt niet. De hekjes moeten altijd het eerste karakter op de regel zijn om herkend te worden door de precompiler. Dit kan wel:
code:
1
2
3
4
5
#ifdef WIN32
#    include <conio.h>
#else
#    include "standard.h"
#endif
serieus?
Bij mij anders prima (MSVC++, maar dat zegt natuurlijk niets)
Het is idd eerste char van de regel, maar volgens mij hoef je de whitespaces niet mee te rekenen

dus dit kan wel:
code:
1
    #include "blaat.h"

maar dit niet:
code:
1
int i; #include "blaat.h"

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 06-09 18:44
Op woensdag 05 juni 2002 16:24 schreef .oisyn het volgende:

[..]

serieus?
Bij mij anders prima
Het is idd eerste char van de regel, maar volgens mij hoef je de whitespaces niet mee te rekenen
"
16 Preprocessing directives [cpp]
1. The first token in the sequence is a # preprocessing token that is either the first character in the source file (optionally after white space containing no newline characters) or that follows white space containing at least one newline character.
"

Mag idd best.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • Soultaker
  • Registratie: September 2000
  • Laatst online: 06-09 19:42
Op woensdag 05 juni 2002 17:49 schreef MSalters het volgende:
16 Preprocessing directives [cpp]
1. The first token in the sequence is a # preprocessing token that is either the first character in the source file (optionally after white space containing no newline characters) or that follows white space containing at least one newline character.
Hmm, hoe ik dan ooit op dat gekke idee gekomen ben :?

Ik zal 't toch niet zelf verzonnen hebben, hoop ik. |:(

Maar goed, ik ben weer wat wijzer.

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
Op woensdag 05 juni 2002 17:51 schreef Soultaker het volgende:

[..]

Hmm, hoe ik dan ooit op dat gekke idee gekomen ben :?

Ik zal 't toch niet zelf verzonnen hebben, hoop ik. |:(

Maar goed, ik ben weer wat wijzer.
Hoezo ISO standaard?? Gewoon Soultaker standaard :P

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

gcc pakte dit mij laats niet, ik moest het # echt op de eerste karakter zetten.
Pagina: 1