In the following example, is it possible to declare test() with such a signature so it would print 6
? I would like this for style and readability purposes, so that it's clear that the function takes an array of exactly 6 chars, and it actually can get this information with sizeof
.
#include <stdio.h>
void test( char foo[ 6 ] )
{
printf( "%zu\n", sizeof( foo ) ); // Prints 8 as it's a pointer now, but I want 6 as in an array
}
int main()
{
char foo[ 6 ];
printf( "%zu\n", sizeof( foo ) ); // Prints 6, which is what I want
test( foo );
return 0;
}
So far, the best I could come up with is this:
typedef char Foo[ 6 ];
void test( Foo foo )
{
printf( "%zu\n", sizeof( Foo ) ); // Works, but it doesn't even use foo, and I want to get the size information from foo! What if I change the signature of the function later? I would have to update this line too, which is something I'd like to avoid
}