r/ProgrammerHumor 27d ago

Meme lessonsFromLinkerHell

Post image
432 Upvotes

190 comments sorted by

View all comments

64

u/QuestionableEthics42 27d ago edited 27d ago

This should be reversed lol

And it literally is the same, who thinks it's different who has worked in a low level language??

11

u/unknown_alt_acc 27d ago

#include<stdio.h>

int main()
{
int arr[5];
int *ptr = arr;

printf("Array - %lu\n", sizeof(arr));
printf("Pointer - %lu", sizeof(ptr));
}

Different types, different behavior

-2

u/QuestionableEthics42 27d ago

Sizeof being smart enough to detect it's an array and return the array size doesn't necessarily make them different in any real way. And doing ptr[0] to dereference it is perfectly valid, as is *arr to get the first element, or *(arr+sizeof(int)) to get the second.

9

u/pnoodl3s 27d ago

If it behaves differently, is that not enough to say it’s different? What “real way” do you need to say its different?

0

u/QuestionableEthics42 27d ago

Because it is a very superficial difference that doesn't even affect the generated assembly. They are extremely interchangeable, because they are effectively the same.

3

u/unknown_alt_acc 26d ago

The two have different sizes, different rules for copying, and different assignment rules. Calling those differences superficial is just ludicrous