Recently I've been wondering if it's possible for the compiler with some flag optimization, avoid copying two arrays to the .rodata
section? Thus, memory addresses would be the same, eg
const char str[7] = "string";
const char str1[7] = "string";
int printf(const char *format, ...);
int main(void) {
if(str == str1)
printf("Endereços de memória iguais");
return 0;
}
So in this example above, is it possible that somehow the compiler uses the same memory addresses?
EDIT:
It does not make much sense at all, of course, it was just a matter of curiosity, I tried to see some flags of optimization but no success.
#include <stdio.h>
void main(void) {
char *str1 = "string";
char *str2 = "string";
if(str == str2) puts("Igual");
}
In the example above, the compiler puts the string literal of the pointer str1
in the .rodata
section and uses the same string , ie the same address to the str2
pointer. So I wanted to know if you could simulate this by doing array . I read the Manpage of the GCC, but I did not find anything relevant in this sense, but thank you anyway for your response.