0
  1. I am migrating php from 5.3 to 5.5.
  2. I am doing cross compilation in freebsd 7 - gcc 4.2.1
  3. Compiling for arm, i386 and powerpc.

a source file is not compiling. Following is the code similar the real one.

typedef struct _abc {
        char *d;
        size_t s;
        size_t u;
        uint f:1;
        uint _arj:31;
}abc;

unit and other types are defined in a top header file using typedef. I added this line after the first comment.

i get error: bit-field '___arj' has invalid type

i renamed _arj to just arj and it worked. yet i have to find and replace _arj to arj in the code base.

Is there any naming convention for variables used in bit fields?

Jayapal Chandran
  • 10,600
  • 14
  • 66
  • 91
  • `uint` is not a standard type - how is it defined ? – Paul R Jan 21 '15 at 14:53
  • It is defined in a top header as typedef unsigned int uint; i have also updated my question with this. – Jayapal Chandran Jan 21 '15 at 14:55
  • If I change `uint` to `unsigned`, it works. But if, as you say, `uint` is defined on your system, your example code should compile with no problem. – ryyker Jan 21 '15 at 14:58
  • no it is single underscore but in the error it shows 3 underscores – Jayapal Chandran Jan 21 '15 at 15:00
  • 1
    If `_arj` is defined somewhere else, (i.e. typed), its usage here would be syntactically wrong. By the way, what you have in your example code does not seem to match the error you indicate: i.e. `___arj`, does not match `_arj` – ryyker Jan 21 '15 at 15:01
  • not _arj but i meant uint is defined in a top header file – Jayapal Chandran Jan 21 '15 at 15:02
  • i changed unit to unsigned int and i still get the error – Jayapal Chandran Jan 21 '15 at 15:07
  • 2
    `gcc -E` gives the preprocessor output, `gcc -E -dM` the macros defined. If `_arj` isn't a macro (but it seems to be one), the code should be OK. – mafso Jan 21 '15 at 15:08
  • @ryyker it seems that there is a conflict with the name _arj. when i renamed it to arj or _srj or _zxarj it worked. – Jayapal Chandran Jan 21 '15 at 15:15
  • 1
    Identifiers should NOT start wth an underscore http://c-faq.com/decl/namespace.html . Structure members are a bit different, but it is still a bad habit. Just don't do it. – wildplasser Jan 21 '15 at 15:22

1 Answers1

0

About implementation reserved names, it's generally a bad idea to start names with a leading underscore. A leading double underscore is actually a violation. Here's an excerpt from the glibc manual:

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs.

And a link to the page I got that from: http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html

tipaye
  • 454
  • 3
  • 6