In code I would typically use:
#include <stdlib.h>
void dref1(char **blah)
{
(*blah)[0] = 'a';
(*blah)[1] = 'z';
(*blah)[2] = 0x00;
}
/* or */
void dref2(char **blah)
{
char *p = *blah;
*p++ = 'w';
*p++ = 't';
*p = 0x00;
}
int main(void)
{
char *buf = malloc(3);
dref1(&buf);
puts(buf);
dref2(&buf);
puts(buf);
free(buf);
return 0;
}
My question is if it is possible / how to dereference and increment pointer directly:
**blah = 'q'; /* OK as (*blah)[0] ? */
(*blah)++; /* Why not this? */
*((*blah)++) = 'w'; /* ;or. */
...
Yes, we can. Just test a litter. I think you have the idea.
The problem with using
blahthe way you write, is, that when you come back to main, not only the content of the buffer is changed (correctly as you whant), but the pointerbufitself too. That may be not what you want, and definetivily not what you need to free.Test: