{"id":2694,"date":"2011-12-02T18:26:52","date_gmt":"2011-12-02T17:26:52","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=2694"},"modified":"2011-12-02T18:26:52","modified_gmt":"2011-12-02T17:26:52","slug":"matlab-mex-on-linux-using-c-style-comments-in-c-mex-files","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=2694","title":{"rendered":"MATLAB mex on Linux: Using C++ style comments in C mex files"},"content":{"rendered":"<p>I recently spent a lot of time optimizing a MATLAB user&#8217;s code and made extensive use of mex files written in C.\u00a0 Now, one of the habits I have gotten into is to mix C and C++ style comments in my C source code like so:<\/p>\n<pre>\r\n\/* This is a C style comment *\/\r\n\r\n\/\/ This is a C++ style comment\r\n<\/pre>\n<p>For this particular project I did all of the development on Windows 7 using MATLAB 2011b and Visual Studio 2008 which had no problem with my mixing of comments.  Move over to Linux, however, and it&#8217;s a very different story.  When I try to compile my mex file<\/p>\n<pre>\r\nmex block1.c -largeArrayDims \r\n<\/pre>\n<p>I get the error message <\/p>\n<pre>\r\nblock1.c:48: error: expected expression before \u2018\/\u2019 token\r\n<\/pre>\n<p>The fix is to call mex as follows:<\/p>\n<pre>\r\nmex block1.c -largeArrayDims CFLAGS=\"\\$CFLAGS -std=c99\"\r\n<\/pre>\n<p>Hope this helps someone out there.  For the record, I was using gcc and MATLAB 2011a on 64bit Scientific Linux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently spent a lot of time optimizing a MATLAB user&#8217;s code and made extensive use of mex files written in C.\u00a0 Now, one of the habits I have gotten into is to mix C and C++ style comments in my C source code like so: \/* This is a C style comment *\/ \/\/ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[53,11,7],"tags":[],"class_list":["post-2694","post","type-post","status-publish","format-standard","hentry","category-making-matlab-faster","category-matlab","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-Hs","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2694"}],"version-history":[{"count":3,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2694\/revisions"}],"predecessor-version":[{"id":3969,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2694\/revisions\/3969"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}