TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An Interesting Pointer Puzzle

1 pointsby denniskubesalmost 11 years ago

1 comment

kazinatoralmost 11 years ago
Something is overlooked. Note that:<p><pre><code> int *a[] = { 1, 2, 3 } </code></pre> violates a constraint in the C language; an ISO C conforming implementation must issue a diagnostic --- and, additionally, it may stop translating and reject the program.<p>Why? Because expressions of type int are being used to initialize elements of type pointer to int, without a cast.<p>The first step is operating your compiler such that you get the required diagnostics out of it, or at least the important ones, and then some. For instance, with gcc:<p><pre><code> # C90 gcc -Wall -ansi ... # some would add -pedantic # C99 gcc -Wall -std=c99 ... </code></pre> and then, don&#x27;t ignore diagnostics that are &quot;mere&quot; warnings!<p>And, of course, passing a pointer argument to a &quot;%d&quot; conversion specifier in printf is undefined behavior.
评论 #8176168 未加载