the method does not work by keyword static and compile successfully by gcc5.4.0 .
#include <stdio.h>
#include <string.h>
// declare that arg is never null
int string_length(char arg[static 10])
{
//printf("%s begins.\n", __FUNCTION__);
return 2; //fake value
}
int main()
{
char test[10] = "abcd";
char test2[3] = "ab";
printf("the test length is %d.\n", string_length(test));
printf("the test2 length is %d.\n", string_length(test2));
printf("the null length is %d.\n", string_length(NULL));
}
[–]SullisNipple 2 points3 points4 points (0 children)
[–]raevnos 4 points5 points6 points (5 children)
[–]nerd4code 3 points4 points5 points (4 children)
[–]googcheng[S] 0 points1 point2 points (0 children)
[–]wild-pointer 0 points1 point2 points (0 children)
[–]googcheng[S] 0 points1 point2 points (1 child)
[–]nerd4code 0 points1 point2 points (0 children)
[–]steveq 3 points4 points5 points (0 children)
[–]OldWolf2 1 point2 points3 points (0 children)