A query
hi I am new to c programming and had just started learning it . My friends recommended me to use gcc compilers . but i dont know where will i get this compiler and how to use this . my operating system is Windows XP SP2 . please let me know what should i do ? Thanking You Sincerely, Harsh
zero and pointer conversions in g++
I have this test code that I think g++ is selecting the wrong function when the second argument is a zero. If compiled with HAVE_ASCII_DEFAULT 1 it selects read(const char*, const char*) instead of read(const char*, const Variant&), for test2a/test3a. If compiled with HAVE_ASCII_DEFAULT 0 compilation fails because test2a/test3a are ambiguous. Shouldn't all of the tests select the Variant function, or am I missing something? Why do I have to explicitly create a Variant when the argument is zero? Tested w/ g++ 3.4.3 (Mandrakelinux 10.2 3.4.3-7mdk) and 4.0.1 (self compiled) TIA, Thomas PS please CC as I'm not subscribed #include #include #define HAVE_ASCII_DEFAULT 1 using std::string; using std::ostream; using std::cout; using std::endl; class Variant { public: enum Type { Invalid, Bool, Int, String }; Variant() : i(), b(), s(), type(Invalid) { ; } Variant(Type t) : i(), b(), s(), type(t) { ; } Variant(bool b) : i(), b(b), s(), type(Bool) { ; } Variant(int i) : i(i), b(), s(), type(Int) { ; } Variant(const string& s) : i(), b(), s(s), type(String) { ; } const char* type_name() const; friend ostream& operator<<(ostream& os, const Variant& v); private: int i; int b; string s; Type type; }; const char* Variant::type_name() const { switch(type) { case Bool: return "Bool"; case Int: return "Int"; case String: return "String"; default: break; } return "Invalid"; } ostream& operator<<(ostream& os, const Variant& v) { os << "Variant(" << v.type_name(); switch(v.type) { case Variant::Bool: os << ", " << (v.b? "true": "false"); break; case Variant::Int: os << ", " << v.i; break; case Variant::String: os << ", \"" << v.s.c_str() << '\"'; break; default: break; } return os << ')'; } class Config { public: Config() { ; } string read(const char* pKey, const string& aDefault) const; #if HAVE_ASCII_DEFAULT string read(const char* pKey, const char* aDefault) const; #endif Variant read(const char* pKey, const Variant& aDefault) const; }; #if HAVE_ASCII_DEFAULT string Config::read( const char *pKey, const char *aDefault ) const { if (!aDefault) return read(pKey, string()); return read(pKey, string(aDefault)); } #endif string Config::read( const char *pKey, const string& aDefault ) const { cout << __PRETTY_FUNCTION__ << '\t' << (pKey && *pKey? pKey: "null") << endl << "\taDefault = \"" << aDefault.c_str() << '"' << endl; return aDefault; } Variant Config::read( const char *pKey, const Variant &aDefault ) const { cout << __PRETTY_FUNCTION__ << '\t' << (pKey && *pKey? pKey: "null") << endl << "\taDefault = " << aDefault << endl; return aDefault; } int main(int, char**) { Config config; // bool config.read("test1", true); config.read("test2a", false); config.read("test2b", Variant(false)); config.read("test3a", bool()); config.read("test3b", Variant(bool())); return 0; }
Thumb optimization question
I have one question. So... have small sample programm. [code] int bar( int ); int foo( int a, int b ) { return bar( a + b ); } [/code] If I compille it with out -thumb parameter, i have very clean code. add r0, r1, r0 bx lr But with -thumb parameter have unopimized code. add r1, r1, r0 mov r0, r1 bx lr All diff of it outrage on '*.27.combine' (key -da) optimization step. But I long time can't understad how it work. Can anybody help me with it? -- Regards, Ivan
Re: A query
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Harsh Chandra wrote: > > I am new to c programming and had just started learning it . My > friends recommended me to use gcc compilers . but i dont know where > will i get this compiler and how to use this . my operating system is > Windows XP SP2 . please let me know what should i do ? Wrong list - this is a list for discussing development *of* GCC itself, not how to use it or where to obtain it. As for your question, see MinGW: http://www.mingw.org/ If you want a complete UNIX-like environment on Windows (along with GCC), see Cygwin: http://www.cygwin.com/ Thanks, Ranjit. - -- Ranjit Mathew Email: rmathew AT gmail DOT com Bangalore, INDIA.Web: http://ranjitmathew.hostingzero.com/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDsNVIYb1hx2wRS48RAsH2AJ0VRIF/zwd+QA/NdxD7qQuKIxAS1ACfRcnw UlU0yKcCoj42gN6jOOTbi80= =PrmX -END PGP SIGNATURE-
Re: weakref miscompiling libgfortran
On 25/12/2005, at 8:51 PM, Richard Henderson wrote: On Sun, Dec 25, 2005 at 07:36:16PM -0800, Geoff Keating wrote: That targetm.binds_local_p is no longer reliable is a serious bug. What's wrong with it? It should be answering 'false' for a weakref... It doesn't. Exchanging the TREE_PUBLIC check for the binds_local_p check was the first thing I tried. At which point I realized that we have Real Problems with this feature at the moment. The code in default_binds_local_p_1 says: /* Weakrefs may not bind locally, even though the weakref itself is always static and therefore local. */ else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))) local_p = false; which comment, now that I reread it, is a little confused, but the code looks fine, and it worked for me on Darwin. Perhaps you have a local patch which is affecting this? We've had Real Problems with this feature since it was introduced. I expect it'll take at least another two or three months before it settles down and starts to work on most targets; that's only to be expected for such a far-reaching change to GCC's capabilities. smime.p7s Description: S/MIME cryptographic signature