* warning about anonymous type
@ 2007-05-23 14:17 Shriramana Sharma
0 siblings, 0 replies; only message in thread
From: Shriramana Sharma @ 2007-05-23 14:17 UTC (permalink / raw)
To: Linux C Programming List
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-05-23 14:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-23 14:17 warning about anonymous type Shriramana Sharma
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.