<!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">

<p style="color: #777777;">
<a href="https://gitlab.com/rwmjones">Richard W.M. Jones</a>
<a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1544#note_853664582">commented</a>:
</p>
<div style="">
<p dir="auto">There's actually a trick using <code>typeof</code> which avoids redefining each variable type (and it's more type safe).  However I'm not sure if it requires a GCC extension or not.  See example:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" v-pre="true" style="border-radius: 2px; margin: 0 0 8px; padding: 8px 12px; border: 1px solid #dbdbdb;"><code><span id="LC1" class="line" lang="plaintext">#include <stdio.h>                                                              </span>
<span id="LC2" class="line" lang="plaintext">#include <stdlib.h>                                                             </span>
<span id="LC3" class="line" lang="plaintext">#include <assert.h>                                                             </span>
<span id="LC4" class="line" lang="plaintext">#include <tss2/tss2_esys.h>                                                     </span>
<span id="LC5" class="line" lang="plaintext">#include <dlfcn.h>                                                              </span>
<span id="LC6" class="line" lang="plaintext">                                                                                </span>
<span id="LC7" class="line" lang="plaintext">typeof(Esys_Initialize) (*my_Esys_Initialize);                                  </span>
<span id="LC8" class="line" lang="plaintext">typeof(Esys_Finalize) (*my_Esys_Finalize);                                      </span>
<span id="LC9" class="line" lang="plaintext">                                                                                </span>
<span id="LC10" class="line" lang="plaintext">int                                                                             </span>
<span id="LC11" class="line" lang="plaintext">main ()                                                                         </span>
<span id="LC12" class="line" lang="plaintext">{                                                                               </span>
<span id="LC13" class="line" lang="plaintext">  void *dl = dlopen ("libtss2-esys.so.0", RTLD_NOW);                            </span>
<span id="LC14" class="line" lang="plaintext">  assert (dl);                                                                  </span>
<span id="LC15" class="line" lang="plaintext">                                                                                </span>
<span id="LC16" class="line" lang="plaintext">  my_Esys_Initialize = dlsym (dl, "Esys_Initialize");                           </span>
<span id="LC17" class="line" lang="plaintext">  assert (my_Esys_Initialize);                                                  </span>
<span id="LC18" class="line" lang="plaintext">  my_Esys_Finalize = dlsym (dl, "Esys_Finalize");                               </span>
<span id="LC19" class="line" lang="plaintext">  assert (my_Esys_Finalize);                                                    </span>
<span id="LC20" class="line" lang="plaintext">                                                                                </span>
<span id="LC21" class="line" lang="plaintext">  ESYS_CONTEXT *ctx;                                                            </span>
<span id="LC22" class="line" lang="plaintext">  if (my_Esys_Initialize (&ctx, NULL, NULL)) {                                  </span>
<span id="LC23" class="line" lang="plaintext">    fprintf (stderr, "Esys_Initialize failed\n");                               </span>
<span id="LC24" class="line" lang="plaintext">    exit (1);                                                                   </span>
<span id="LC25" class="line" lang="plaintext">  }                                                                             </span>
<span id="LC26" class="line" lang="plaintext">                                                                                </span>
<span id="LC27" class="line" lang="plaintext">  fprintf (stderr, "ctx = %p\n", ctx);                                          </span>
<span id="LC28" class="line" lang="plaintext">                                                                                </span>
<span id="LC29" class="line" lang="plaintext">  my_Esys_Finalize (&ctx);                                                      </span>
<span id="LC30" class="line" lang="plaintext">  exit (0);                                                                     </span>
<span id="LC31" class="line" lang="plaintext">}                                                                               </span></code></pre>
<copy-code></copy-code>
</div>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1544#note_853664582">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/29846af89ae7050ad2a5c12150698e2a/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/1544#note_853664582"}}</script>


</p>
</div>
</body>
</html>