Domanda

I've seen a lot of the minimal requirements that an ANSI C compiler must support like 31 arguments to a function, and most of the numbers seem to make some kind of sense.

However, I cannot see the reasoning for supporting at least 509 characters in a source line. 511 or 512 would make more sense, but 509 seems kind of arbitrary.

What is the reason for this number?

È stato utile?

Soluzione

This perhaps is to take account of possible CR + LF + '\0' characters and have a string representation of each line still fit into 512 bytes of memory.

Altri suggerimenti

The C11 dr 5.2.4.1 limits are different than given by the OP. I suspect they come from C89.

4095 characters in a logical source line

4095 characters in a string literal (after concatenation)


[Edit] @jwodder suggested a more complete answer was needed.

Best I can provide: 512 bytes was the most common sector size for floppy, diskette and hard drive media circa mid 80 to mid 90s and likely contributed, along with @bizzehdee & @DigitalTrauma thoughts as to the curious 509 limit.

It was a very popular buffer size.

straight from this question

Perhaps 509 is intended to allow for a 512-byte buffer with two bytes for a "\r\n" line terminator and one for a '\0' string terminator.

I have no source, but I thought it's the two " characters and the \0 character that make up these 512 characters. I don't think that the 2 characters are for CRLF for 2 reasons: These are not default characters you must write there, and for LINUX it's only LF. That's why I say it's the two " characters.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top