mastodon.gamedev.place is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server focused on game development and related topics.

Server stats:

5.1K
active users

#include

5 posts5 participants2 posts today
Leah Neukirchen<p><span class="h-card" translate="no"><a href="https://mastodon.social/@antondollmaier" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>antondollmaier</span></a></span> <span class="h-card" translate="no"><a href="https://mastodon.social/@jpmens" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>jpmens</span></a></span> no, it was an unnececessary <a href="https://blahaj.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a></p>
Julian Andres Klode 🏳️‍🌈<p>I want my compiler to convert this into a single 64-bit integer comparison:</p><p><a href="https://mastodon.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;cstdint&gt;<br><a href="https://mastodon.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;tuple&gt;</p><p>struct priority {<br> uint16_t padding;<br> uint16_t dynamic;<br> uint16_t staticp;<br> int16_t index;</p><p> bool operator&lt;(const priority &amp;other) const;<br>};<br>bool priority::operator&lt;(const priority &amp;other) const<br>{<br> return std::tie(index, staticp, dynamic, padding) &lt; std::tie(other.index, other.staticp, other.dynamic, other.padding);<br>}</p>
Shafik Yaghmour<p>Retro C++ quiz #31</p><p>Given the following in C and C++</p><p>// Assume we have math.h<br><a href="https://hachyderm.io/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;math.h&gt;</p><p>// file or global scope<br>double d = sqrt(2.0);</p><p>This is, without checking:</p><p>A. Valid C and C++<br>B. Valid C<br>C. Valid C++<br>D. Neither Valid C or C++</p><p><a href="https://hachyderm.io/tags/Cplusplus" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Cplusplus</span></a><br><a href="https://hachyderm.io/tags/Cpppolls" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Cpppolls</span></a></p>
Stephen Brennan<p><span class="h-card" translate="no"><a href="https://mastodonapp.uk/@ljs" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>ljs</span></a></span> The libdrgn API is unstable, so there's not even a distro package anywhere that you could do <a href="https://snake.club/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;drgn.h&gt; or -ldrgn right now.</p><p>That said, I know it gets internal use at Meta, and there are examples in the repo.</p><p>I've actually thought it would be interesting to combine libdrgn with a userspace BPF JIT that supports CO-RE, so we could use drgn's type system to resolve type references and execute BPF/kernel like (read-only) code at native speeds in userspace with drgn 🤔</p>
SASANO Takayoshi<p><a href="https://social.mikutter.hachune.net/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;stdio.h&gt;<br><a href="https://social.mikutter.hachune.net/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;fcntl.h&gt;<br><a href="https://social.mikutter.hachune.net/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;unistd.h&gt;<br><a href="https://social.mikutter.hachune.net/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;string.h&gt;</p><p><a href="https://social.mikutter.hachune.net/tags/define" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>define</span></a> MAX_ARGS 16</p><p>int main(int argc, char *argv[])<br>{<br> int i, fds[MAX_ARGS];</p><p> memset(fds, ~0, sizeof(fds));<br> for (i = 1; i &lt; argc &amp;&amp; i &lt; MAX_ARGS; i++) {<br> fds[i] = open(argv[i], O_RDONLY);<br> if (fds[i] &gt;= 0) printf("%d\n", fds[i]);<br> }<br> for (i = 1; i &lt; argc &amp;&amp; i &lt; MAX_ARGS; i++)<br> if (fds[i] &gt;= 0) close(fds[i]);<br> return 0;<br>}</p>
witch_t *navi<p><span class="h-card"><a class="u-url mention" href="https://mk.absturztau.be/@prisixia" rel="nofollow noopener noreferrer" target="_blank">@<span>prisixia</span></a></span> <span class="h-card"><a class="u-url mention" href="https://tech.lgbt/@lina" rel="nofollow noopener noreferrer" target="_blank">@<span>lina</span></a></span> <span class="h-card"><a class="u-url mention" href="https://gaysex.cloud/@sodiboo" rel="nofollow noopener noreferrer" target="_blank">@<span>sodiboo</span></a></span> <span class="h-card"><a class="u-url mention" href="https://fedi.askiiart.net/@hanna" rel="nofollow noopener noreferrer" target="_blank">@<span>hanna</span></a></span> <span class="h-card"><a class="u-url mention" href="https://transfem.social/@puppygirlhornypost2" rel="nofollow noopener noreferrer" target="_blank">@<span>puppygirlhornypost2</span></a></span> i just use getline ~w~</p><pre><code>#include &lt;stddef.h&gt; <a class="hashtag" href="https://social.vlhl.dev/tag/include" rel="nofollow noopener noreferrer" target="_blank">#include</a> &lt;stdio.h&gt; <a class="hashtag" href="https://social.vlhl.dev/tag/include" rel="nofollow noopener noreferrer" target="_blank">#include</a> &lt;stdlib.h&gt; <a class="hashtag" href="https://social.vlhl.dev/tag/include" rel="nofollow noopener noreferrer" target="_blank">#include</a> &lt;string.h&gt; int main(void) { char *name = NULL; char *profession = NULL; ssize_t len; size_t size; printf("Hello, what is your name? "); if ((len = getline(&amp;name, &amp;size, stdin)) == -1) return EXIT_FAILURE; name[len - 1] = '\0'; printf("What do you do for a living? "); if ((len = getline(&amp;profession, &amp;size, stdin)) == -1) return EXIT_FAILURE; profession[len - 1] = '\0'; printf("%s the %s went out on a stroll in the park.\n", name, profession); free(name); free(profession); return 0; } </code></pre>
Microsoft DevBlogs<p>🚀 Exciting news in the 1.25 release of the C++ extension for VS Code! Now, GitHub Copilot can provide instant symbol summaries, and you can customize recursive <a href="https://dotnet.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> processing settings.</p><p>This means improved insights into undocumented code and better IntelliSense performance tailored to your project needs.</p><p>Want to understand those tricky codebases faster? Just hover over symbols to get quick summaries! 🎉 Download the update and experience the enhancements firstha</p>
Luke T. Shumaker<p><span class="h-card" translate="no"><a href="https://60228.dev/@leo" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>leo</span></a></span> But linux-man-pages is good at consistently telling you to not just `<a href="https://social.coop/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;foo.h&gt;` but also when you need to `<a href="https://social.coop/tags/define" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>define</span></a> GNU_SOURCE` or `<a href="https://social.coop/tags/define" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>define</span></a> POSIX_SOURCE 2000XXXXL` or whatever or even sometimes getting different versions of the function based on which you define (even if the official GNU info manual isn't great at noting such things).</p>
Foone🏳️‍⚧️<p>when I look up FooBarA() and MSDN says it's in winfoo.h, I assume that I need to do just <a href="https://digipres.club/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;winfoo.h&gt; for it to work.</p><p>that's how C headers work basically everywhere else, after all</p>
Hugo Mills<p><span class="h-card" translate="no"><a href="https://mstdn.social/@stux" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>stux</span></a></span> "Your browser is not officially supported"... "Sign in here"...</p><p><a href="https://mstdn.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;octopus-nope.gif&gt;</p><p>Ho hum.</p>
the first osdev// we use this number later as a literal; make sure it is imported<br><a class="hashtag" href="https://donotsta.re/tag/include" rel="nofollow noopener noreferrer" target="_blank">#include</a> 12
Ilja A. Iwas<p><a href="https://social.iwascoding.com/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;Foundation/Foundation.h&gt;</p>
void friend<p>Okay so it's all very new to this <a href="https://tech.lgbt/tags/C" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>C</span></a> quiz author so pls excuse dumb mistakes in this quiz, but assuming I didn't make any dumb mistakes, what's wrong in the following C program?</p><p>EDIT: as predicted, the quiz was rubbish and has been edited</p><pre><code>#include &lt;pthread.h&gt;<br><br>_Atomic char * _Atomic p;<br><br>void *thr1(void *arg) {<br> _Atomic char *my_p = p;<br> if (my_p) *my_p = 0;<br> return 0;<br>}<br><br>void *thr2(void *arg) {<br> _Atomic char c = ((p = &amp;c), 0);<br> while (1);<br>}<br><br>int main(void) {<br> pthread_t t1, t2;<br> pthread_create (&amp;t1, 0, thr1, 0);<br> pthread_create (&amp;t2, 0, thr2, 0);<br>}<br></code></pre>
48kRAM<p><a href="https://oldbytes.space/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;primalscream.h&gt;</p>
JohnOCFII<p>And here is what those changes do:</p><p>Changes made:</p><p><a href="https://twit.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;stdio.h&gt; – Includes the standard I/O library needed for printf.</p><p>int main(void) – Specifies that main returns an int and takes no arguments.</p><p>return 0; – Returns 0 to indicate successful program execution.</p>
GNU/翠星石<span class="h-card"><a class="u-url mention" href="https://freesoftwareextremist.com/users/tatsumoto" rel="nofollow noopener noreferrer" target="_blank">@<span>tatsumoto</span></a></span> <span class="h-card"><a class="u-url mention" href="https://lab.nyanide.com/users/nyanide" rel="nofollow noopener noreferrer" target="_blank">@<span>nyanide</span></a></span> Even a program as trivial as "hello world" is 4MiB in Rust.<br><br>Some rust-lover set me this rust program to demonstrate how to get a reasonably-sized hello world in Rust;<br>#![no_std]<br>#![no_main]<br><br>use core::ffi::CStr;<br><br>#[no_mangle]<br>pub extern fn main(_argc: i32, _argv: *const *const core::ffi::c_char) -&gt; i32 {<br> unsafe{libc::printf(CStr::from_bytes_with_nul_unchecked("hello world\n\0".as_bytes()).as_ptr());}<br> 0<br>}<br><br>#[cfg(not(test))]<br>#[panic_handler]<br>fn panic(_:&amp;core::panic::PanicInfo)-&gt;! {<br> loop{}<br>}<br><br>(Or you can just write in C);<br><a class="hashtag" href="https://freesoftwareextremist.com/tag/include" rel="nofollow noopener noreferrer" target="_blank">#include</a> &lt;stdio.h&gt;<br>int main() { printf("hello world\n"); }<br><br><br>Furthermore, the only rust compiler is almost certainly compromised with multiple backdoors, as the only compiler that can compile rust is rustc version N-1.<br><br>That's right, if you want to bootstrap rust, you need to bootstrap gcc, then use it to compile an ancient Rust compiler implementation (written in C++) and use that to compile every single Rust version in sequences (requiring hundreds of gigabytes of storage for text and countless CPU cycles).<br><br>I'd be highly impressed if no-one managed to slip a backdoor into any of the massive Rust releases from the past several years - I suspect there are several backdoors, as there's plenty of space to fit them in such massive binaries.<br><br><br>Furthermore, the typical Rust program uses hundreds of dependencies, all statically linked.<br><br>Rust also often forces you to write 10 times lines to do something that takes 1 line in C.<br><br>Remember that most security bugs in software are logic errors (i.e. wrong logic for checking passwords etc) and even if Rust is memory safe and doesn't have memory bugs, you end up with 10x the logic errors and therefore 10x the security bugs, as you have 10x more code.<br><br><br>All that is needed is enhanced static and dynamic analyzers for C - for example there should be an gcc option where it won't compile the GNU C unless the program is free of memory errors and then such could be run on the tried and tested C codebases to tease out the remaining memory bugs - but that software is under a freedom-defending license, thus it must be rewritten under a weak one instead.<br><br>As you can see, the Rust cancer needs to be to cut away with a plasma cutter and a corrosion-protective coating applied.
Karl Baron<p>It looks like CW by default auto-includes any Mac headers you need, but at the same time stdlib stuff like "strlen" isn't working even with a manual <a href="https://bitbang.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;strings.h&gt; which is the point where I'm starting to look at "maybe I should read a book instead of just poking at things randomly!" (2/2)</p>
Jevin Sweval<p>How to politely use assert in a header (gcc/clang/msvc/what else?):</p><p><a href="https://mastodon.social/tags/pragma" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>pragma</span></a> push_macro("NDEBUG")<br><a href="https://mastodon.social/tags/undef" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>undef</span></a> NDEBUG<br><a href="https://mastodon.social/tags/include" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>include</span></a> &lt;assert.h&gt;<br>// your asserts should properly assert<br><a href="https://mastodon.social/tags/pragma" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>pragma</span></a> pop_macro("NDEBUG")<br>// nobody has 2 know</p><p>Your vendor’s assert.h should be able to be included multiple times with NDEBUG defined or not.</p>
Jann Horn<p><span class="h-card" translate="no"><a href="https://infosec.exchange/@jduck" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>jduck</span></a></span> I mean, if it convinces you...</p><pre><code>$ cat blub.c<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;<br>struct foo {<br> long a;<br> int b;<br> int arr[];<br>};<br>int main(void) {<br> struct foo *a = malloc(sizeof(struct foo) + sizeof(int)*3);<br> struct foo *b = malloc(sizeof(struct foo) + sizeof(int)*3);<br> if (!a || !b)<br> return 1;<br><br> a-&gt;a = 1;<br> a-&gt;b = 2;<br> for (int i=0; i&lt;3; i++)<br> a-&gt;arr[i] = i + 123456;<br><br> b-&gt;a = 101;<br> b-&gt;b = 102;<br> for (int i=0; i&lt;3; i++)<br> b-&gt;arr[i] = i + 100;<br><br> *b = *a;<br><br> for (int i=0; i&lt;3; i++)<br> printf("%d ", b-&gt;arr[i]);<br> printf("\n");<br>}<br>$ gcc -o blub blub.c<br>$ ./blub<br>123456 101 102<br></code></pre>
Jann Horn<p>Why does the C standard not mention any UB in its definition of offsetof()? Is it implicit somewhere else that doing <code>offsetof(struct foo, arr[SIZE_MAX])</code> on a struct containing a flexible array member is UB?</p><p>Both GCC and clang don't diagnose anything here and compile it to a "return 0":</p><pre><code>#include &lt;stddef.h&gt;<br>#include &lt;inttypes.h&gt;<br>struct foo {<br> int a;<br> int arr[];<br>};<br>unsigned long func(void) {<br> return offsetof(struct foo, arr[SIZE_MAX]);<br>}<br></code></pre><p><a href="https://godbolt.org/z/rx7rqvh7j" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="">godbolt.org/z/rx7rqvh7j</span><span class="invisible"></span></a></p>