I am trying to convert some code from a dynamically typed language to C. Please bear with me since I have no practical experience with C.
I have a dispatch function that decides how to convert it based on the value of the flag argument.
void output_dispatcher(char *str, int strlen, int flag) {
char output[501];
char *result;
switch (flag) {
case 0:
result = str;
break;
case 1:
result = convert_type1(output, str, strlen);
len = strlen(result);
break;
}
}
I currently have 5 different output converters, and all of them (even the future) guarantee only 300-500 characters. From my reading, it is preferable to use a heap variable than dynamically allocate space on the stack, if possible. A function declaration for one is as follows:
static char * convert_type1(char *out, const char *in, int inlen);
strlen ,
, ,
. ,
, , ?
, " ".
void output_dispatcher(char *str, int strlen, int flag) {
char output[501];
switch (flag) {
case 0:
output = str;
break;
case 1:
strlen = convert_type1(output, str, strlen);
break;
}
}
, ?