problème avec mes constantes
Bonjour, j'ai encore un pb avec mes #define. Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include<stdlib.h>
#include<stdio.h>
#include<assert.h>
#ifndef MSG_ERROR
#define MSG_ERROR fprintf(stderr,"Error in file %s in function %s at line %u:\n",__FILE__,__FUNCTION__,__LINE__)
#else
#error Constant MSG_ERROR is already defined. End of compilation
#endif
#ifndef EXIT_PRGM
#define EXIT_PRGM exit(EXIT_FAILURE)
#else
#error Constant EXIT_PRGM is already defined. End of compilation
#endif
#ifndef ERROR_ALLOC_MEM
#define ERROR_ALLOC_MEM MSG_ERROR;fprintf(stderr,"Error allocation memory\nExit program\n");exit(EXIT_FAILURE)
#else
#error Constant ERROR_ALLOC_MEM is already defined. End of compilation
#endif
int main()
{
double * p=malloc(3*sizeof(*p));
//if(p==NULL) ERROR_ALLOC_MEM;
assert(p!=NULL);
p[0]=1; p[1]=2; p[2]=3;
printf("%f\t%f\t%f\n",p[0],p[1],p[2]);
return(EXIT_SUCCESS);
} |
ici la sortie est correcte :
Citation:
1.000000 2.000000 3.000000
en revanche si mon main devient
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
int main()
{
double * p=malloc(3*sizeof(*p));
if(p==NULL) ERROR_ALLOC_MEM;
//assert(p!=NULL);
p[0]=1; p[1]=2; p[2]=3;
printf("%f\t%f\t%f\n",p[0],p[1],p[2]);
return(EXIT_SUCCESS);
} |
j'obtiens la sortie :
Citation:
Error in file cste.c in function main at line 30:
Error allocation memory
Exit program
savez-vous pourquoi ?
Merci