Package: libc6-dev
Version: 2.3.5-6

Hi,

I'm trying to compile this:

<clip>
/* #define __USE_MISC */

#include <sys/mman.h>
#include <unistd.h>

static int pageCount(size_t len)
{
        unsigned long ps = getpagesize();
        return ((len + (ps - 1)) / ps) * ps;
}

static void* execMalloc(size_t requested_length)
{
        const int MMAP_BASE_ADDRESS = 1024*1024;
        void* addr = (mmap (((void *) MMAP_BASE_ADDRESS),
                                                
(size_t)pageCount(requested_length),
                                                (PROT_EXEC | PROT_READ | 
PROT_WRITE),
                                                (MAP_PRIVATE | MAP_ANONYMOUS),
                                                /* Ignored by GNU/Linux, 
required by FreeBSD and Solaris. */
                                                (-1),
                                                0));
        return ((addr == MAP_FAILED) ? 0 : addr);
}
</clip>

with gcc 4.0.1.  The above fails to compile with -std=c89:

<clip>
[EMAIL PROTECTED]:~/dev$ gcc -std=c89 -c mmap.c
mmap.c: In function 'execMalloc':
mmap.c:14: error: 'MAP_ANONYMOUS' undeclared (first use in this function)
mmap.c:14: error: (Each undeclared identifier is reported only once
mmap.c:14: error: for each function it appears in.)
</clip>

If I don't specify -std=c89, it works nicely.  If I define __USE_MISC,
then it compiles again.

Is this the way it should work?

I am using Debian GNU/Linux 2.6.

[EMAIL PROTECTED]:~/dev$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix
--program-suffix=-4.0 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)

Reply via email to