Issue Details (XML | Word | Printable)

Key: PCC-376
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Nicolas Joly
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

__builtin_offsetof result is not a constant

Created: 29/Aug/11 04:14 PM   Updated: 03/Sep/11 11:10 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

NetBSD 5.99.55 NetBSD 5.99.55 (LANFEUST) #0: Mon Aug 29 13:17:23 CEST 2011 amd64
pcc 1.1.0.DEVEL 20110829 for x86_64-unknown-netbsd5.99.55

 Description  « Hide
The following piece of code (extracted from GNU m4), does not compile with pcc (no problem with gcc) ... __builtin_offsetof result is not a constant.

njoly@lanfeust [check/pcc]> cat offsetof.c
#include <stddef.h>

struct s { char c; };
enum { e = offsetof(struct s, c) };

int main() { return 0; }

njoly@lanfeust [check/pcc]> pcc offsetof.c; echo $?
offsetof.c, line 4: constant expected
njoly@lanfeust [check/pcc]> gcc offsetof.c; echo $?

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 03/Sep/11 09:46 AM
Fixed now. Needed one more rmpconv() when discarding casts.

Nicolas Joly added a comment - 03/Sep/11 11:10 AM

I just encountered a similar behavior when using offsetof for bit-field definitons.

njoly@petaure [~]> cat offsetof.c
#include <stddef.h>

struct s1 { char c1; char c2; };
struct s2 { int i : offsetof(struct s1, c2) ? 1 : -1; };

int main() { return 0; }

njoly@petaure [~]> pcc offsetof.c; echo $?
offsetof.c, line 4: constant expected
njoly@petaure [~]> gcc offsetof.c; echo $?

NB: Using sizeof(struct s1) instead of offsetof here, does not exhibit the problem.