win32 compile problem: illegal symbol __pragma

I suspect something is wrong with my installation of PGI 13.6 on Windows. Can you help to identify what is wrong?

type x.c
#include <malloc.h>
int main(){return 0;}

pgcc --version
PGI Workstation 13.6

pgcc 13.6-0 32-bit target on x86-64 Windows -tp sandybridge
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2013, STMicroelectronics, Inc. All Rights Reserved.

pgcc -c x.c
PGI Workstation 13.6
PGC-S-0040-Illegal use of symbol, warning (C:/Program Files/PGI/Microsoft Open Tools 11/include\malloc.h: 237)
PGC-W-0156-Type not specified, ‘int’ assumed (C:/Program Files/PGI/Microsoft Open Tools 11/include\malloc.h: 237)

PGC/x86 Windows 13.6-0: compilation completed with severe errors

malloc.h uses __pragma(warning(push)) on the mentioned line. Pgcc expects _Pragma(“string”), I think.

Hi dima2011,

Sorry but you can’t include “malloc.h” on Windows. MS recently added a bunch of non-standard MS specific code to the header file and we weren’t able to work around them. If you’re just using “malloc”, then there’s no need to include “malloc.h”. It will be declared implicitly.

  • Mat

Hi Mat,

Thank you for clarification. However, one must declare malloc() anyway, because return type ‘int’ of implicit declaration is different from actual ‘void*’ returned by malloc(). On a 64-bit system if you are ‘just using malloc’ you will get what you deserve - likely and hopefully a segmentation fault. To make the application portable you have to declare malloc() explicitly. With pgcc on windows there are these options, at least:

  1. Declare the missing function or functions like this
    #if defined(PGIC)
    extern void *malloc(size_t);
    #include <malloc.h>

  2. Or make pgcc understand Microsoft’s __pragma keyword:
    #if defined(PGIC)
    #define __pragma(arg) _PRAGMA_STRINGIFY(arg)
    #define _PRAGMA_STRINGIFY(a) _PRAGMA(#a)
    #define _PRAGMA(a) _Pragma(a)
    #include <malloc.h>

What is your recommendation?
Does PGI have plans to support Microsoft’s extensions on Windows?