From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: warning about anonymous type
Date: Wed, 23 May 2007 19:47:47 +0530 [thread overview]
Message-ID: <46544D0B.30904@gmail.com> (raw)
I need to have a single global variable containing some members. I read
that using a singleton class is not recommended and really I don't have
a need for a class. So I just tested g++ -c on a code fragment:
---------------------------
struct {
int a, b, c ;
} mystruct ;
class {
int a, b, c ;
} myclass ;
---------------------------
g++ -c gives me the warnings:
singleton.cpp:7: warning: non-local variable ‘<anonymous struct>
mystruct’ uses anonymous type
singleton.cpp:13: warning: non-local variable ‘<anonymous class>
myclass’ uses anonymous type
However, testing the struct declaration in C does not give any warnings.
OK, C++ is pickier than C, so this is fine. But I don't really know what
to make of the warnings that g++ gave me. What is the potential problem
if a non-local variable has an anonymous type?
Apparently if a **local** variable has an anonymous type it is OK, since
I did not get this warning when I put the mystruct and myclass
definitions into main(). But I don't get the logic behind:
1) the warning
2) the distinction between local and nonlocal in this case
Please explain.
With thanks as always,
Shriramana Sharma.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
reply other threads:[~2007-05-23 14:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46544D0B.30904@gmail.com \
--to=samjnaa@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).