div_t typesAuthors: Jay Ghiron
Date: 2026-03-20
Submitted against: C23
Status: Open
The current definitions of the division types do not clearly state
whether or not they can have members other than quot or rem:
The
div,ldiv, andlldivfunctions return a structure of typediv_t,ldiv_t, andlldiv_t, respectively, comprising both the quotient and the remainder. The structures shall contain (in either order) the membersquot(the quotient) andrem(the remainder), each of which has the same type as the argumentsnumeranddenom.
(C23 7.24.7.2 "The div, ldiv, and lldiv functions" paragraph 3.)
The
imaxdivfunction returns a structure of typeimaxdiv_tcomprising both the quotient and the remainder. The structure shall contain (in either order) the membersquot(the quotient) andrem(the remainder), each of which has typeintmax_t.
(C23 7.8.3.2 "The imaxdiv function" paragraph 3.)
The other definitions of structure types use the wording "at least the following members" which clearly indicates that they can contain further members. The definitions of the division types do not use such wording that clearly indicates there can be other members, but also do not clearly forbid including other members. An example of where this matters is:
#include<stdlib.h>
struct{div_t d;int x;}s={1,2,3};
If there can be other members this might be invalid or give the member
x of s a value of zero. Moreover, the quot and rem members of
s.d could either individually be zero or both be zero if the other
members can be added between quot and rem or before both quot
and rem. It seems unintended to allow definitions of the division
types that contain members other than quot and rem.
Modify C23 7.24.7.2 paragraph 3:
The structures shall contain exactly (in either order) the members
quot(the quotient) andrem(the remainder), each of which has the same type as the argumentsnumeranddenom.
Modify C23 7.8.3.2 paragraph 3:
The structure shall contain exactly (in either order) the members
quot(the quotient) andrem(the remainder), each of which has typeintmax_t.