So I have this code which works fine
#include <stdio.h>
#define B(X) &X
struct abc{
char temp[2];
};
void print(char *string)
{
printf("%s\n", string);
}
int main()
{
struct abc *pAbc = malloc(sizeof(struct abc));
pAbc->temp[0] = 'a';
pAbc->temp[1] = '\0';
print(pAbc->temp);
free(pAbc);
return 0;
}
but this does not work
#include <stdio.h>
#define B(X) &X
struct abc{
char temp[2];
};
void print(char **string)
{
printf("%s\n", *string);
}
int main()
{
struct abc *pAbc = malloc(sizeof(struct abc));
pAbc->temp[0] = 'a';
pAbc->temp[1] = '\0';
print(B(pAbc->temp));
free(pAbc);
return 0;
}
as I understand it the macro defination should return the address of the variable.
This function works fine with int.
EDIT:
Sorry I forgot to mention what I wanted to do, I want to pass a pointer to a pointer to the function, since I want to do it only for some compile paths I want to set an option like
if #defined WIN32
print(B(varible))
elif #defined GCC
print(varible)