Do standard Windows .ini files allow comments?
comments, file, ini, windows
Solution
Windows INI API support for:
- Line comments: yes, using semi-colon `;`
- Trailing comments: No
The authoritative source is the Windows API function that reads values out of INI files
GetPrivateProfileString
Retrieves a string from the specified section in an initialization file.
The reason "full line comments" work is because the requested value does not exist. For example, when parsing the following `ini` file contents:
[Application]
UseLiveData=1
;coke=zero
pepsi=diet ;gag
#stackoverflow=splotchy
Reading the values:
- `UseLiveData`: `1`
- `coke`: not present
- `;coke`: not present
- `pepsi`: `diet ;gag`
- `stackoverflow`: not present
- `#stackoverflow`: `splotchy`
Update: I used to think that the number sign (#) was a pseudo line-comment character. The reason using leading # works to hide `stackoverflow` is because the name `stackoverflow` no longer exists. And it turns out that semi-colon (`;`) is a line-comment.
But there is no support for trailing comments.
Problem
Are comments allowed in Windows ini files? (...assuming you're using the GetPrivateProfileString api functions to read them...) ``` [Section] Name=Value ; comment ; full line comment ``` And, is there a proper spec of the .INI file format anywhere? Thanks for the replies - However maybe I wasn't clear enough. It's only the format as read by Windows API Calls that I'm interested in. I know other implementations allow comments, but it's specifically the MS Windows spec and implementation that I need to know about.