# Compilation warning on offsetof in 5.4 and trunk

- Thread: https://externals.io/message/53728
- Original archive: https://news-web.php.net/php.internals/53728
- Started by jerome@loyet.net on 2011-07-03T01:07:48+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #53728 — jerome@loyet.net — 2011-07-03T01:07:48+00:00

URL: https://externals.io/message/53728#53728

Hi,

in 5.4 and trunk, there is compilation warnings all pointing to
STD_PHP_INI_ENTRY


/home/fat/dev/php-src/trunk/sapi/fpm/fpm/fpm_main.c:1465:109: warning:
cast from pointer to integer of different size
/home/fat/dev/php-src/trunk/sapi/fpm/fpm/fpm_main.c:1466:85: warning:
cast from pointer to integer of different size


the warnings appear in sapis (cgi, fpm, ...) and extensions (standard,
...) and the problem comes from the XOffsetOf macro which is expanded
to offsetof defined in Zend/zend_operators.h whit the following code
added in revisions 311662 and 312264:

#ifndef offsetof
#define offsetof(t,f) \
  ((int)(&((t*)0)->f))
#endif

Before this addition, XOffsetOf was expanded to
  ((long) (((char *) (&(((t*)((void *)0))->f))) - ((char *) ((void *)0))))

which is defined at the end of main/php.h.

Two questions:
1- is this possible to change Zend/zend_operators.h to use the old
macros ? (short term solution)
2- Why not using the build-in POSIX offsetof (man offsetof) when
available ? (long term solution)

thx
++ jerome

PS: i'm compiling on 64 bits linux

---

## #53730 — Gustavo Lopes — 2011-07-03T01:27:16+00:00

URL: https://externals.io/message/53728#53730 · In reply to: #53728

>
> the warnings appear in sapis (cgi, fpm, ...) and extensions (standard,
> ...) and the problem comes from the XOffsetOf macro which is expanded
> to offsetof defined in Zend/zend_operators.h whit the following code
> added in revisions 311662 and 312264:
>
> #ifndef offsetof
> #define offsetof(t,f) \
>   ((int)(&((t*)0)->f))
> #endif
>

Yes, the cast should be changed to (size_t)(uintptr_t).

I have also hit this problem a month ago. At the time I think I commented  
on IRC using (int)(intptr_t) instead could avoid problems like in "if  
(offsetof(x) - 5 < 0)", but since the C standard calls for a «expand[ing]  
to an integer constant expression that has type size_t»,  
(size_t)(uintptr_t) seems preferable.

-- 
Gustavo Lopes

---

## #53731 — Felipe Pena — 2011-07-03T01:29:27+00:00

URL: https://externals.io/message/53728#53731 · In reply to: #53728

Hi,

2011/7/2 Jérôme Loyet <jerome@loyet.net>:
> Hi,
>
> in 5.4 and trunk, there is compilation warnings all pointing to
> STD_PHP_INI_ENTRY
>
>
> /home/fat/dev/php-src/trunk/sapi/fpm/fpm/fpm_main.c:1465:109: warning:
> cast from pointer to integer of different size
> /home/fat/dev/php-src/trunk/sapi/fpm/fpm/fpm_main.c:1466:85: warning:
> cast from pointer to integer of different size
>
>
> the warnings appear in sapis (cgi, fpm, ...) and extensions (standard,
> ...) and the problem comes from the XOffsetOf macro which is expanded
> to offsetof defined in Zend/zend_operators.h whit the following code
> added in revisions 311662 and 312264:
>
> #ifndef offsetof
> #define offsetof(t,f) \
>  ((int)(&((t*)0)->f))
> #endif
>
> Before this addition, XOffsetOf was expanded to
>  ((long) (((char *) (&(((t*)((void *)0))->f))) - ((char *) ((void *)0))))
>
> which is defined at the end of main/php.h.
>
> Two questions:
> 1- is this possible to change Zend/zend_operators.h to use the old
> macros ? (short term solution)

I've removed this offsetof definition introduced in r311662, it seems
have been added accidentaly, as the code in this revision do not use
it.

-- 
Regards,
Felipe Pena
