1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "log_macros.h"
int main(int argc, char* argv[]) {
char* abc_string = malloc(sizeof(*abc_string) * 4);
abc_string[0] = 'a';
abc_string[1] = 'b';
abc_string[2] = 'c';
abc_string[3] = '\0';
size_t num_numbers = 3;
int* numbers = malloc(sizeof(*numbers) * num_numbers);
numbers[0] = 5;
numbers[1] = 6;
numbers[2] = 7;
void* a_something = numbers; // for illustration only; do not do this in your code
void* a_something_else = abc_string;
char* s = a_something_else;
log_str(s);
// numbers = abc_string; // ERROR!!!
// // GCC: assignment to ‘int *’ from incompatible pointer type ‘char *’
int n = numbers[1];
free(abc_string);
free(numbers);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2023 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.