bph
bph

Reputation: 11258

struct typedef names that clash with stdlib

I have an issue where one of my struct typedefs, mode_t, clashes with one in the stdlib

mode_t is already defined in sys/types.h

whats best practice in this instance? to rename my struct to something else or is there some other way to resolve the clash?

Upvotes: 1

Views: 379

Answers (3)

LearningC
LearningC

Reputation: 3162

If your program names clash with the library variable names, change the names in your program.

Upvotes: 1

doptimusprime
doptimusprime

Reputation: 9395

If the name conflicts in C program, then you need to rename your structure. In C++, you can use namespace.

Or if you want to use this name, then do not include sys/types.h.

Upvotes: 2

Bathsheba
Bathsheba

Reputation: 234665

Never have your own structure name or variable name that ends in _t. Regard all such names as reserved by either the compiler or the standard library.

Although technically legal by the C standard, many platforms (e.g. POSIX) explicitly forbid it.

Your best option is to rename your structure.

Upvotes: 6

Related Questions