user2559503
user2559503

Reputation: 289

Purpose of #pragma comment(user) in Visual and #pragma Comment in gcc

Visual c++ and gcc both have these directives that they define as "used to add a comment to the executable file." What exactly is the purpose of this? It seems that these comments would be embedded somewhere in binary and impossible to locate within the executable. Are they retrievable or useful in any way?

Upvotes: 0

Views: 381

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490128

You seem to have misread the description of this #pragma. Microsoft's documentation says:

Places a general comment in the object file. The commentstring parameter contains the text of the comment. This comment record is ignored by the linker.

At least according to this documentation, it would appear that (since the record is ignored by the linker) such a comment would only embed the string into the object file, not the executable.

The obvious purpose would be to embed something like a copyright string into an object file being shipped as a library for developers to use. Such libraries are typically licensed to allow a developer to link the object files from the library into an executable, but not to redistribute the object files themselves.

In such a case, the effect would be that if the developer linked the object file to an executable, the copyright notice would disappear (and it's up to the developer to provide attribution if the license requires it), but if they re-distribute the object files, the original copyright notice would remain intact, more or less like a digital watermark.

Upvotes: 1

Related Questions