/* Buttondown A Markdown/MultiMarkdown/Pandoc HTML output CSS stylesheet Author: Ryan Gray Date: 15 Feb 2011 Revised: 21 Feb 2012 General style is clean, with minimal re-definition of the defaults or overrides of user font settings. The body text and header styles are left alone except title, author and date classes are centered. A Pandoc TOC is not printed, URLs are printed after hyperlinks in parentheses. Block quotes are italicized. Tables are lightly styled with lines above and below the table and below the header with a boldface header. Code blocks are line wrapped. All elements that Pandoc and MultiMarkdown use should be listed here, even if the style is empty so you can easily add styling to anything. There are some elements in here for HTML5 output of Pandoc, but I have not gotten around to testing that yet. */ /* NOTES: Stuff tried and failed: It seems that specifying font-family:serif in Safari will always use Times New Roman rather than the user's preferences setting. Making the font size different or a fixed value for print in case the screen font size is making the print font too big: Making font-size different for print than for screen causes horizontal lines to disappear in math when using MathJax under Safari. */ /* ---- Front Matter ---- */ /* Pandoc header DIV. Contains .title, .author and .date. Comes before div#TOC. Only appears if one of those three are in the document. */ body {counter-reset: h2} h1 {counter-reset: h2} h2 {counter-reset: h3} h3 {counter-reset: h4} h4 {counter-reset: h5} h5 {counter-reset: h6} h1.nocount:before, h2.nocount:before, h3.nocount:before, h4.nocount:before, h5.nocount:before, h6.nocount:before { content: ""; counter-increment: none } div#header, header { /* Put border on bottom. Separates it from TOC or body that comes after it. */ border-bottom: 1px solid #aaa; margin-bottom: 0.5em; } .title /* Pandoc title header (h1.title) */ { text-align: center; } .author, .date /* Pandoc author(s) and date headers (h2.author and h3.date) */ { font-size: 3ex; text-align: center; } /* Pandoc table of contents DIV when using the --toc option. NOTE: this doesn't support Pandoc's --id-prefix option for #TOC and #header. Probably would need to use div[id$='TOC'] and div[id$='header'] as selectors. */ div#TOC, nav#TOC { /* Put border on bottom to separate it from body. */ border-bottom: 1px solid #aaa; margin-bottom: 0.5em; } ins { color: #009E73 } del { color: #E69F00 } #diffToggles { display: none } @media screen { #TOC { width: 35%; float: left; overflow: hidden; } #diffToggles { display: block } } @media print { div#TOC, nav#TOC { /* Don't display TOC in print */ display: none; } } /* ---- Headers and sections ---- */ h1, h2, h3, h4, h5, h6 { font-family: "Helvetica Neue", Helvetica, "Liberation Sans", Calibri, Arial, sans-serif; /* Sans-serif headers */ /* font-family: "Liberation Serif", "Georgia", "Times New Roman", serif; /* Serif headers */ page-break-after: avoid; /* Firefox, Chrome, and Safari do not support the property value "avoid" */ } /* Pandoc with --section-divs option */ div div, section section /* Nested sections */ { margin-left: 2em; /* This will increasingly indent nested header sections */ } p {} blockquote { font-style: italic; } li /* All list items */ { } li > p /* Loosely spaced list item */ { margin-top: 1em; /* IE: lack of space above a
*/ } ul /* Whole unordered list */ { } ul li /* Unordered list item */ { } ol /* Whole ordered list */ { } ol li /* Ordered list item */ { } hr {} /* ---- Some span elements --- */ sub /* Subscripts. Pandoc: H~2~O */ { } sup /* Superscripts. Pandoc: The 2^nd^ try. */ { } em /* Emphasis. Markdown: *emphasis* or _emphasis_ */ { } em > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > p > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > * > p > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > p > ins > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } blockquote > * > p > ins > em /* Emphasis within emphasis: *This is all *emphasized* except that* */ { font-style: normal; } /* ---- Links (anchors) ---- */ a /* All links */ { /* Keep links clean. On screen, they are colored; in print, they do nothing anyway. */ text-decoration: none; } @media screen { a:hover { /* On hover, we indicate a bit more that it is a link. */ text-decoration: underline; } } @media print { a { /* In print, a colored link is useless, so un-style it. */ color: black; background: transparent; } a[href^="http://"]:after, a[href^="https://"]:after { /* However, links that go somewhere else, might be useful to the reader, so for http and https links, print the URL after what was the link text in parens */ content: " (" attr(href) ") "; font-size: 90%; } } /* ---- Images ---- */ img { /* Let it be inline left/right where it wants to be, but verticality make it in the middle to look nicer, but opinions differ, and if in a multi-line paragraph, it might not be so great. */ vertical-align: middle; } div.figure /* Pandoc figure-style image */ { /* Center the image and caption */ margin-left: auto; margin-right: auto; text-align: center; font-style: italic; } p.caption /* Pandoc figure-style caption within div.figure */ { /* Inherits div.figure props by default */ } /* ---- Code blocks and spans ---- */ pre, code { background-color: #FFFFD0; /* BEGIN word wrap */ /* Need all the following to word wrap instead of scroll box */ /* This will override the overflow:auto if present */ white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ /* END word wrap */ } pre /* Code blocks */ { /* Distinguish pre blocks from other text by more than the font with a background tint. */ padding: 0.5em; /* Since we have a background color */ border-radius: 5px; /* Softens it */ /* Give it a some definition */ border: 1px solid #aaa; /* Set it off left and right, seems to look a bit nicer when we have a background */ margin-left: 0.5em; margin-right: 0.5em; } pre.yacc, code.yacc { background-color: #f0f0f0; } pre.yacc /* Code blocks */ { /* Distinguish pre blocks from other text by more than the font with a background tint. */ padding: 0.0em; /* Since we have a background color */ border-radius: 5px; /* Softens it */ /* Give it a some definition */ border: 0px solid #aaa; /* Set it off left and right, seems to look a bit nicer when we have a background */ margin-left: 0.0em; margin-right: 0.0em; } @media screen { pre { white-space: pre; /* Dotted looks better on screen and solid seems to print better. */ border: 1px dotted #777; } } code /* All inline code spans */ { } p > code, li > code /* Code spans in paragraphs and tight lists */ { /* Pad a little from adjacent text */ padding-left: 2px; padding-right: 2px; } li > p code /* Code span in a loose list */ { /* We have room for some more background color above and below */ padding: 2px; } span.option { color: blue; text-decoration: underline; } /* ---- Math ---- */ span.math /* Pandoc inline math default and --jsmath inline math */ { /* Tried font-style:italic here, and it messed up MathJax rendering in some browsers. Maybe don't mess with at all. */ } div.math /* Pandoc --jsmath display math */ { } span.LaTeX /* Pandoc --latexmathml math */ { } eq /* Pandoc --gladtex math */ { } /* ---- Tables ---- */ /* A clean textbook-like style with horizontal lines above and below and under the header. Rows highlight on hover to help scanning the table on screen. */ table { border-collapse: collapse; border-spacing: 0; /* IE 6 */ border-bottom: 2pt solid #000; border-top: 2pt solid #000; /* The caption on top will not have a bottom-border */ /* Center */ margin-left: auto; margin-right: auto; } thead /* Entire table header */ { border-bottom: 1pt solid #000; background-color: #eee; /* Does this BG print well? */ } tr.header /* Each header row */ { } tbody /* Entire table body */ { } /* Table body rows */ tr { } tr.odd:hover, tr.even:hover /* Use .odd and .even classes to avoid styling rows in other tables */ { background-color: #eee; } /* Odd and even rows */ tr.odd {} tr.even {} td, th /* Table cells and table header cells */ { vertical-align: top; /* Word */ vertical-align: baseline; /* Others */ padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.2em; padding-bottom: 0.2em; } /* Removes padding on left and right of table for a tight look. Good if thead has no background color*/ /* tr td:last-child, tr th:last-child { padding-right: 0; } tr td:first-child, tr th:first-child { padding-left: 0; } */ th /* Table header cells */ { font-weight: bold; } tfoot /* Table footer (what appears here if caption is on top?) */ { } caption /* This is for a table caption tag, not the p.caption Pandoc uses in a div.figure */ { caption-side: top; border: none; font-size: 0.9em; font-style: italic; text-align: center; margin-bottom: 0.3em; /* Good for when on top */ padding-bottom: 0.2em; } /* ---- Definition lists ---- */ dl /* The whole list */ { border-top: 2pt solid black; padding-top: 0.5em; border-bottom: 2pt solid black; } dt /* Definition term */ { font-weight: bold; } dd+dt /* 2nd or greater term in the list */ { border-top: 1pt solid black; padding-top: 0.5em; } dd /* A definition */ { margin-bottom: 0.5em; } dd+dd /* 2nd or greater definition of a term */ { border-top: 1px solid black; /* To separate multiple definitions */ } /* ---- Footnotes ---- */ a.footnote, a.footnoteRef { /* Pandoc, MultiMarkdown footnote links */ font-size: small; vertical-align: text-top; } a[href^="#fnref"], a.reversefootnote /* Pandoc, MultiMarkdown, ?? footnote back links */ { } @media print { a[href^="#fnref"], a.reversefootnote /* Pandoc, MultiMarkdown */ { /* Don't display these at all in print since the arrow is only something to click on */ display: none; } } div.footnotes /* Pandoc footnotes div at end of the document */ { } div.footnotes li[id^="fn"] /* A footnote item within that div */ { } table tr td,th { border-right: 1px solid; border-left: 1px solid; } /* You can class stuff as "noprint" to not print. Useful since you can't set this media conditional inside an HTML element's style attribute (I think), and you don't want to make another stylesheet that imports this one and adds a class just to do this. */ @media print { .noprint { display:none; } }
2026-04-01
integration into IS ISO/IEC 9899:202y
C document ID: C4172
| document number | date | comment |
|---|---|---|
| n3543 | 202504 | original proposal |
| n3707 | 202509 | remove floating types |
place in <stdlib.h> |
||
| make the interfaces unsequenced | ||
| n3762 | 202512 | revise wording for promotions |
use unsigned long
in the example instead of size_t |
||
| n3868 | 202604 | remove the claim for ICE |
| revise wording for the type choice | ||
move to <stdint.h> |
||
Generic features to compute minimum and maximum value of two given integer values is notoriously challenging in C. The difficulties with such features are as follows
Previous revisions of this paper also discussed versions of these macros that would result in integer constant expressions if the arguments are so. This aspect did not find as wide approval as the feature in general, so we drop this idea for now. In can be added later without problems.
We propose to add type-generic macros that solve all these problems for all integer value and type combinations. Namely:
In particular, if one type is signed and the other is unsigned, we have to ensure that the result type can hold the result and that no sign conversion occurs when converting to the result type.
The macro stdc_min chooses the
signed type for the result. This choice is motivated as follows:
s is 0 or positive, the
other value u may only hold the
minimum if u ≤ s and thus then u ≤ SMAX where SMAX is the maximum value of the signed
type.Thus the signed type is always able to hold the result of the minimum operation.
The macro stdc_max chooses the
common real type for the result. This choice is motivated as
follows:
s is 0 or positive, no
sign conversion is necessary.Thus no sign conversion is necessary to store the result in the common real type.
The proposed features have to be implemented side effect free (7.14)
and thus, seen as function interfaces, they should be pure in the CS
sense of the term. So, as we have already have done for the bit
manipulation macros, for these new interfaces we add the [[unsequenced]]
attribute.
After discussion in WG14, we propose to add the features to the <stdint.h>
header in a subclause of their own.
The choice for the macro names is guided by the fact that the min and max identifiers are abundantly used in user
code, not only for functions or macros that perform these operations,
but also as variable names that store the respective minimum or maximum
value in a given situation. The prefix stdc_, which is already reserved for
identifiers with external linkage, seemed the most natural one:
sufficiently short and unambiguous.
Implementations of minimum and maximum macros or functions there are plenty. Even the current C standard provides a handful of slightly different interfaces for maximum macros and functions, but only for floating types. Then, in the field an abundant number of implementations of varying properties and quality are added to that picture.
The goal of this paper is to propose a unification to all these interfaces and their behavior, such that programmers find reliable implementations of these features in their C library.
The reference implementation that is available on the WG14 git (and
that we are able to provide on request) is not meant to suggest any
particular way in which these features should be implemented, but only
to prove that an implementation is possible as of today with relatively
small effort. Besides a lot of C23-only features, this reference
implementation uses only the __COUNTER__ pseudo macro (which is accepted
for inclusion into C2Y).
Our expectation is that compilers will provide buildins for these features and that the macros proposed here will then only serve as stubs to ensure standard conformance.
In 7.23, bump the value of __STDC_VERSION_STDINT_H__.
Then add a new clause
7.23.7 Minimum and maximum type-generic macros on integer values
1 These macros perform the minimum and maximum operations of two integers. They are applicable to pairs of values of any integer type and return the numerically exact result of the operation. In the following
AandBdenote the type of the first and second argument of an invocation after performing integer promotions.
2 Synopsis
#include <stdint.h>
minType stdc_min(A a, B b) [[unsequenced]];
maxType stdc_max(A a, B b) [[unsequenced]];Description
3 These type-generic macros apply integer promotions to their arguments and then compute the minimum and maximum value of the results.
4 The result type
maxTypeis the common real type of the typesAandBafter the usual arithmetic conversions (6.3.2.8).
5 If
AandBare both signed types or both unsigned types, the result typeminTypeis their common real type after the usual arithmetic conversions (6.3.2.8). Otherwise,minTypeis the signed type of the two.
Returns
6 The result of the operation is the value of the numerically lesser (respectively greater) promoted argument converted to type
minTypeormaxType, respectively.
7 NOTE The types
minTypeandmaxTypeare able to represent the numerical result of the corresponding operation.
8 Example
#include <stdint.h>
unsigned long n = ULONG_MAX;
auto max1 = stdc_max(n, 0); // (unsigned long)n
auto min1 = stdc_min(n, 0); // (signed int)0
auto max2 = stdc_max(n, 0u); // (unsigned long)n
auto min2 = stdc_min(n, 0u); // (unsigned long)0
auto max3 = stdc_max(n, (char)0); // (unsigned long)n
auto min3 = stdc_min(n, (char)0); // (unsigned long)0 or (signed int)0
auto max4 = stdc_max(3wb, 7wbu); // (unsigned _BitInt(3))7
auto min4 = stdc_min(3wb, 7wbu); // (signed _BitInt(3))3
auto max5 = stdc_max(-1wb, 255wbu); // (unsigned _BitInt(8))255
auto min5 = stdc_min(-1wb, 255wbu); // (signed _BitInt(2))-1
auto max6 = stdc_max(-1wbu, 255wbu); // (unsigned _BitInt(8))255
auto min6 = stdc_min(-1wbu, 255wbu); // (unsigned _BitInt(8))1For
min1, one of the promoted arguments tostdc_minhas a signed type, so the result type is that signed type. Conversely, formin2both promoted arguments have an unsigned type, and so the result is the common real type. The type ofmin3depends on whether or notcharcan hold negative values and of its width. Ifcharhas no negative values and the same width asintit promotes tounsigned intand thus the result type isunsigned long; otherwise the result type issigned int. The type ofmax4is the common real type ofsigned _BitInt(3)(for3wb) andunsigned _BitInt(3)(for7wbu) which isunsigned _BitInt(3). Formin4with the same arguments, the result type is signed type of the two,signed _BitInt(3). Formin5, since one of the types is signed the result is that typesigned _BitInt(2). Formin6,-1wbuis the maximum value ofunsigned _BitInt(1)which is1; since both of the types are unsigned the result is converted to the common real typeunsigned _BitInt(8).
I’d like to thank Aaron Ballman, Christoph Grüninger, Joseph Myers, Philipp Klaus Krause, and Robert Seacord for their suggestions.