<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<div style="">
<p dir="auto">Uhg, that is hard-to-recognize issue with typedef'ing pointers. A good reason not to do so.</p>
<p dir="auto">gcc -Wall shows it:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">#include <string.h></span>
<span id="LC2" class="line" lang="plaintext">#include <stdio.h></span>
<span id="LC3" class="line" lang="plaintext"></span>
<span id="LC4" class="line" lang="plaintext">typedef char *str;</span>
<span id="LC5" class="line" lang="plaintext">typedef const char *str_const;</span>
<span id="LC6" class="line" lang="plaintext"></span>
<span id="LC7" class="line" lang="plaintext">int main(void)</span>
<span id="LC8" class="line" lang="plaintext">{</span>
<span id="LC9" class="line" lang="plaintext"> str s1 = strdup("a");</span>
<span id="LC10" class="line" lang="plaintext"> str_const s2 = strdup("b");</span>
<span id="LC11" class="line" lang="plaintext"> const str s3 = strdup("c"); // same as 'str const s3'</span>
<span id="LC12" class="line" lang="plaintext"></span>
<span id="LC13" class="line" lang="plaintext"> *s1 = 'x'; // OK</span>
<span id="LC14" class="line" lang="plaintext"> *s2 = 'y'; // error</span>
<span id="LC15" class="line" lang="plaintext"> *s3 = 'z'; // OK</span>
<span id="LC16" class="line" lang="plaintext"> s3 = NULL; // error, s3 is 'char * const' not a 'const char *'</span>
<span id="LC17" class="line" lang="plaintext"></span>
<span id="LC18" class="line" lang="plaintext"> return 0;</span>
<span id="LC19" class="line" lang="plaintext">}</span></code></pre>
<p dir="auto">That means we need an extra typedef to make use of 'const' for typedef'ed pointers. Ugly.</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #777;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/merge_requests/1000#note_172906659">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/sent_notifications/b213d068f10e7cb5ac0ed00c485f6e3d/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/merge_requests/1000#note_172906659"}}</script>
</p>
</div>
</body>
</html>