{"id":3537,"date":"2014-08-24T16:48:58","date_gmt":"2014-08-24T16:48:58","guid":{"rendered":"http:\/\/www.readytext.co.uk\/?p=3537"},"modified":"2014-09-11T09:23:51","modified_gmt":"2014-09-11T09:23:51","slug":"what-is-texs-memoryword-structure-in-c","status":"publish","type":"post","link":"https:\/\/www.readytext.co.uk\/?p=3537","title":{"rendered":"What is TeX&#8217;s memoryword structure in C?"},"content":{"rendered":"<p>Just a brief post, partly to record this for my own use. If you read the source code of TeX you will see references to a data structure called a <em>memoryword<\/em>. It is very carefully defined in the source file <code>texmfmem.h<\/code>, using various <code>#ifdef<\/code> blocks to account for endian-type and the &#8220;flavour&#8221; of TeX you are compiling. So, here is the <code>memoryword<\/code>, stripped to the very basics for my <em>Windows-only<\/em> build of TeX. On my machine, <code>sizeof(memoryword)<\/code> = 8 bytes &ndash; <code>glueratio<\/code> is defined as the type <code>double<\/code> (8 bytes) &ndash; TeX does use the type <code>double<\/code> for glue calculations. From section 109 of the TeX source code:<\/p>\n<blockquote><p>When TEX &#8220;packages&#8221; a list into a box, it needs to calculate the proportionality ratio by which the glue inside the box should stretch or shrink. This calculation does not affect TEX&#8217;s decision making, so the precise details of rounding, etc., in the glue calculation are not of critical importance for the consistency of results on different computers.<\/p><\/blockquote>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#define glueratio double\r\ntypedef unsigned char quarterword  ;\r\ntypedef int integer;\r\ntypedef integer halfword  ;\r\n\r\ntypedef union\r\n{\r\n   struct  {\r\n     int LH, RH;\r\n  } v;\r\n\r\n   struct {\r\n     short B1, B0;\r\n  } u;\r\n\r\n} twohalves;\r\n\r\n\r\ntypedef struct\r\n{\r\n   struct {\r\n     quarterword B3, B2, B1, B0;\r\n  } u;\r\n\r\n} fourquarters;\r\n\r\ntypedef union {\r\n\r\n   glueratio gr;\r\n   twohalves hh;\r\n  \r\n   struct {\r\n     halfword junk;\r\n     integer CINT;\r\n   } u;\r\n\r\n  struct {\r\n     halfword junk;\r\n     fourquarters QQQQ;\r\n  } v;\r\n\r\n} memoryword;\r\n\r\ntypedef union {\r\n  \r\n  struct {\r\n    integer CINT;\r\n  } u;\r\n\r\n  struct\r\n  {\r\n    fourquarters QQQQ;\r\n  } v;\r\n\r\n} fmemoryword;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just a brief post, partly to record this for my own use. If you read the source code of TeX you will see references to a data structure called a memoryword. It is very carefully defined in the source file texmfmem.h, using various #ifdef blocks to account for endian-type and the &#8220;flavour&#8221; of TeX you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,14],"tags":[],"class_list":["post-3537","post","type-post","status-publish","format-standard","hentry","category-c-programming-miscellaneous","category-tex-general"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3537"}],"version-history":[{"count":17,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3537\/revisions"}],"predecessor-version":[{"id":3589,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3537\/revisions\/3589"}],"wp:attachment":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}