I wasn't exactly exactly sure what title I should use for this question, but I'll try to clarify through an explanation:
So the long and short of it is that I want a functions argument to accept both an array AND an integer for the same argument. Not too difficult, just use a pointer right? So I have this:
#define BIT0 (unsigned char){0b00000001}
void foo (unsigned char *ptr_bar)
{
printf("%x", *ptr_bar);
}
void main (void)
{
foo(&BIT0);
}
Works all fine and dandy for a regular value, but in my case I need to be able to inverse the value, so I figured this would work:
#define BIT0 (unsigned char){0b00000001}
void foo (unsigned char *ptr_bar)
{
printf("%x", *ptr_bar);
}
void main (void)
{
foo(&~BIT0);
}
Just invert the value with a bitwise NOT (~) when passing it. No biggie right? Well I get the error
error: lvalue required as unary '&' operand
If I rewrite it as:
#define BIT0 (unsigned char){0b00000001}
void foo (unsigned char *ptr_bar)
{
printf("%x", *ptr_bar);
}
void main (void)
{
foo(&(unsigned char){~BIT0});
}
First off, this is a super ugly solution, and I really don't want to have to use it in my code. It doesn't feel intuitive at all. Second, It works as I wanted it to work initially, but what I believe that this is telling me is that the '~' operator is promoting the unsigned char to an unsigned int. So I have to cast it back to an unsigned char for the function to be able to accept the address. But the error message doesn't really match up with that which is confusing me.
What's going on here? How do I work around this to get the behavior that I want?