J
Joona I Palaste
Timothy Madden said:Hello
I've noticed that 'sizeof (CBuffer::m_pData)' doesn't compile.
Perhaps this is because :: is an invalid token in C?
Timothy Madden said:Hello
I've noticed that 'sizeof (CBuffer::m_pData)' doesn't compile.
Timothy said:Hello
I've noticed that 'sizeof (CBuffer::m_pData)' doesn't compile.
Is this behavior present by chance or there is a good reason for it ?
Perhaps this is because :: is an invalid token in C?
Timothy said:Hello
I've noticed that 'sizeof (CBuffer::m_pData)' doesn't compile.
Timothy Madden said:Ok ok ok ...
I knew I might overlook something when I posted to c.l.c.
However if I have this declaration:
struct CBuffer
{
unsigned char *m_pData;
size_t m_nSize;
};
how should I get the sizeof (*(struct CBuffer *)main).m_pData in a way that
many could say it is nicer ?
(this code really compiles in C, I've tested)
Joona I Palaste said:Perhaps this is because :: is an invalid token in C?
Keith said:.... snip ...
#include <stdio.h>
struct CBuffer
{
unsigned char *m_pData;
size_t m_nSize;
};
#define MEMBER_SIZE(type, member) (sizeof ((type*)0)->member)
int main(void)
{
printf("MEMBER_SIZE(struct CBuffer, m_pData) = %d\n",
(int)MEMBER_SIZE(struct CBuffer, m_pData));
printf("MEMBER_SIZE(struct CBuffer, m_nSize) = %d\n",
(int)MEMBER_SIZE(struct CBuffer, m_nSize));
return 0;
}
CBFalconer said:Er - did you ever try that macro expansion?
Keith said:Yes, I did. I just tried the program again with several different
compilers, and it works properly with no warnings on all of them. I
also ran "gcc -E" (after commenting out the "#include <stdio.h>"), and
the results looked reasonable. It looks like it dereferences a null
pointer, but it doesn't really because the operand of sizeof is not
evaluated (unless it's a VLA, but that's not the case here).
Do you see a problem that I'm missing?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.