{"id":2487,"date":"2016-02-17T08:47:32","date_gmt":"2016-02-17T07:47:32","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=2487"},"modified":"2016-02-17T08:47:32","modified_gmt":"2016-02-17T07:47:32","slug":"fortran-detect-64bit-32bit","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=2487","title":{"rendered":"Fortran: Detect 64bit 32bit"},"content":{"rendered":"<p>Ein m\u00f6glicher Weg zu erkennen ob auf einer 64bit oder 32bit Maschine compiliert wird ist mit Hilfe<br \/>\nvon macros. Die \u00fcblichen macros wie __amd64, __amd64__, __x86_64 __x86_64__ funktionieren unter gfortran (nicht) mehr, da sie nur zeigen ob eine 64Bit Prozessor zur Verf\u00fcgung steht. Und nicht, ob man<br \/>\nauch wirklich f\u00fcr 64bit compiliert. [1]<br \/>\nEs ist nat\u00fcrlich m\u00f6glich untr 64bit OS f\u00fcr 32bit zu compilieren, wenn zum Beispiel nur ein 32bit Compiler zur Verf\u00fcgung steht. Oder zu Testzwecken<\/p>\n<p>Laut doku [2] steht zu diesem Zwecke das macro __LP64__ zur Verf\u00fcgung.<\/p>\n<blockquote><p>__LP64__<br \/>\n_LP64<br \/>\n    These macros are defined, with value 1, if (and only if) the compilation is for a target where long int and pointer both use 64-bits and int uses 32-bit. <\/p><\/blockquote>\n<p>Pointer ist 64bit und integer ist 32bit. So ist es richtig. Alle anderen (M$) machen es falsch.<\/p>\n<p>Nun gibt es leider Compiler, die kein Preprocessing beherrschen. Zum Gl\u00fcck gibt es Fortran 2003<br \/>\nmit dem neuen iso_c_binding Modul. Das Symbol C_INTPTR_T repr\u00e4sentiert die Gr\u00f6\u00dfe eines<br \/>\nPointers und kann als KIND parameter benutzt werden.<\/p>\n<pre><code>\r\nprogram main\r\n  use, intrinsic :: iso_c_binding\r\n  implicit none\r\n  integer(kind=C_INTPTR_T) :: sizeofapointer\r\n  \r\n!__LP64__\r\n!_LP64\r\n! These macros are defined, with value 1, if (and only if) the compilation is for a target where long int and pointer both use 64-bits and int uses 32-bit. \r\n#ifdef __LP64__\r\n  write(*,*) \"64bit detected by macro\"\r\n#else\r\n  write(*,*) \"32bit detected by macro\"\r\n#endif\r\n\r\n  write(*,*) \"C_INTPTR_T\",  C_INTPTR_T\r\nend program\r\n<\/code><\/pre>\n<p>PS: Es ist m\u00f6glich mit gfortran f\u00fcr 32bit zu compilieren. Einfach gfortran-multilib installieren<br \/>\nund dem Compiler -m32 geben.<\/p>\n<p>[1] https:\/\/gcc.gnu.org\/bugzilla\/show_bug.cgi?id=47175<br \/>\n[2] https:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.2.1\/cpp\/Common-Predefined-Macros.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ein m\u00f6glicher Weg zu erkennen ob auf einer 64bit oder 32bit Maschine compiliert wird ist mit Hilfe von macros. Die \u00fcblichen macros wie __amd64, __amd64__, __x86_64 __x86_64__ funktionieren unter gfortran (nicht) mehr, da sie nur zeigen ob eine 64Bit Prozessor zur Verf\u00fcgung steht. Und nicht, ob man auch wirklich f\u00fcr 64bit compiliert. [1] Es ist [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[30],"class_list":["post-2487","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-fortran"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/2487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2487"}],"version-history":[{"count":1,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/2487\/revisions"}],"predecessor-version":[{"id":2488,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/2487\/revisions\/2488"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2487"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}