TIL: many #pascal compilers allowed identifiers of any length, but only examined the first 8 characters to determine what the identifier pointed at.

So `foobarbaz` and `foobarbazqux` are both valid, but refer to the **same** variable!

What I _didn't_ learn was why anyone thought this was a good idea. I assume it was for performance reasons, since Free Pascal doesn't do it anymore (wiki.freepascal.org/Identifier) and 8 makes me guess it has something to do with memory representation.

Anyone know?

@codesections

It was so the compiler and linker didn't have to worry too much about identifier length, yeah. C also had this limitation during that era. That's why functions in the std library are named 'strcat', 'memcpy', etc.

Neither C nor Pascal compilers have had this limitation for decades.

Follow

@codesections Did you know that C compilers are still only required to support up to 4095 characters on a line of source code? If you have a line of code in your C program that's longer than that, the standard doesn't guarantee it has to be compiled correctly :)

@cancel

> Did you know that C compilers are still only required to support up to 4095 characters on a line of source code? If you have a line of code in your C program that's longer than that, the standard doesn't guarantee it has to be compiled correctly :)

I did _not_ know that! And it's per physical line, not per statement? So using a javascipt-style minifier for C source code and having a 1-line program would make the entire thing undefined?

@codesections Sort of :) If the compiler you're using says it's OK to do it in the manual, then it's OK to do it. gcc and clang and msvc could all handle it just fine. I'm not sure if tcc could, though.

@cancel

> Sort of :) If the compiler you're using says it's OK to do it in the manual, then it's OK to do it.

Yeah, fair. I guess I should have said "implementation defined" instead of "undefined"

@cancel when coding rules limits you to 80 characters per line, you don't have any problem with compiler. 🤣 @codesections

@equals_w_equals @cancel @codesections FORTRAN 77 sets the limit at 72, and you also have to spend 8 characters on boilerplate at the start of each line :)

@cancel@merveilles.town @codesections@fosstodon.org Meanwhile, 1980s BASIC would often, e.g. the one on Commodore machines, allow arbitrary length variable names, but only consider the first two (2) characters significant!

Sign in to participate in the conversation
Merveilles

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.