delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/01/07/16:40:36

Message-ID: <002f01c078f2$74cd3c40$ed06893e@oemcomputer>
From: "Stephen Silver" <djgpp AT argentum DOT freeserve DOT co DOT uk>
To: <djgpp-workers AT delorie DOT com>
Subject: namespace std - examples
Date: Sun, 7 Jan 2001 21:40:28 -0000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp-workers AT delorie DOT com

Here are some examples to demonstrate the problems DJGPP currently
has with namespace std.

Consider these four Hello World programs:

// #1
#include <stdio.h>
int main()
{
    puts("Hello, World!");
}

// #2
#include <stdio.h>
int main()
{
    std::puts("Hello, World!");
}

// #3 (invalid)
#include <cstdio>
int main()
{
    puts("Hello, World!");
}

// #4
#include <cstdio>
int main()
{
    std::puts("Hello, World!");
}

At present, all of these (including the invalid one) compile with gpp.
However, this is a little meaningless, because gpp currently uses the
non-ANSI-compliant -fno-honor-std switch by default.  If -fhonor-std
is used (as will presumably be the default in future versions of GCC),
then only #1 and #3 compile.

As a further example, the following valid (but severely contrived) C++
program currently doesn't compile at all, whether or not -fhonor-std
is used:

#include <cmath>
#include <stdio.h>
const char *sin = "avarice";
int main()
{
    printf("%s\n", sin);
}

By contrast with DJGPP, Borland C++ 5.5.1 deals with all the above
examples correctly, i.e., the invalid #3 doesn't compile, but all
the rest compile and run as expected.

Stephen

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019