/* stackframe.c Jeff Ondich, 1 May 2026 This silly program is intended to help us take a look at stack frames. In particular, we're interested in where the buffer in is_palindrome gets stored, what happens on call and ret instructions, etc. Compile like this: gcc -Wall -Werror -g -Og -o stackframe stackframe.c */ #include #include #include #define BUFFER_SIZE 100 void reverse(const char *s, char *t) { if (s == NULL || t == NULL) { return; } int length = strlen(s); for (int k = 0; k < length; k++) { t[k] = s[length - k - 1]; } t[length] = '\0'; } bool is_palindrome(const char *s) { int length = strlen(s); if (length >= BUFFER_SIZE) { return false; } char reversed[BUFFER_SIZE]; reverse(s, reversed); return strcmp(s, reversed) == 0; } int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s string\n", argv[0]); printf(" where string is to be tested as a palindrome\n"); return 1; } if (is_palindrome(argv[1])) { printf("Yes, it's a palindrome\n"); } else { printf("No, it is not a palindrome\n"); } return 0; }