M
MCP
Hello,
I ran the following simple test:
#define ARRAYSIZE(a) (sizeof(a)/sizeof(char))
#include <stdio.h>
#include "chrutil.h"
int main(void) {
char *array = "12345";
char *p = array;
printf("Arraysize: %d\n", ARRAYSIZE(array));
while (*p != '\0') {
printf("Digit: %d\n", dig_to_int(*(p++)));
}
return 0;
}
int dig_to_int(char c) {
if (IS_DIGIT(c)) {
return c - '0';
}
printf("Error: %c\n", c);
}
In this case, the macro ARRAYSIZE or even the simple function sizeof
shows me that "array" has a size of 4?
When I change the line with the array to char array[] = "12345"; it
suddendly shows me that "array" has a size of 6?
How can one explain that?
Regards,
Markus
I ran the following simple test:
#define ARRAYSIZE(a) (sizeof(a)/sizeof(char))
#include <stdio.h>
#include "chrutil.h"
int main(void) {
char *array = "12345";
char *p = array;
printf("Arraysize: %d\n", ARRAYSIZE(array));
while (*p != '\0') {
printf("Digit: %d\n", dig_to_int(*(p++)));
}
return 0;
}
int dig_to_int(char c) {
if (IS_DIGIT(c)) {
return c - '0';
}
printf("Error: %c\n", c);
}
In this case, the macro ARRAYSIZE or even the simple function sizeof
shows me that "array" has a size of 4?
When I change the line with the array to char array[] = "12345"; it
suddendly shows me that "array" has a size of 6?
How can one explain that?
Regards,
Markus