ANSI C : test return from calloc API - differ from windows and ibm cics

The ANSI C code below returns a valid pointer when compiled with Viasual Studio 2010 (Compile as C Code (/TC)) :

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

void main()
    void * p = NULL;
    int i=0;

    p = calloc(0, 100 );

    if ( p != NULL )
        printf ( "Success.\n" );

        free ( p ); 
        p = NULL;
        printf ( "Fail.\n" );

The same code using the C compiler from IBM CICS has different behavior, which returns NULL on API call calloc.
The behavior for Visual Studio 2010 is correct?

Since that test the callback has different effects in both cases.


  • As the documentation from cppreference says:

    If size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage)

    Just don't do that.