- nullptr vs. NULL - 5 Updates
- Aliases - 1 Update
- extern storage class specified - 2 Updates
- Avoid extra indentation in nameless namespaces - 1 Update
- std::complex and std::pow - 2 Updates
Doug Mika <dougmmika@gmail.com>: May 22 01:18PM -0700 Hi to all, When should I use NULL and when should I use nullptr? I've tried to find this on the net but I haven't been able to find anything definitive. The only thing I did find is that using nullptr anulls ambiguity when calling an overloaded function such as: foo(int x); foo(int* x); with a call: foo(NULL); //but when would we ever use this? |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: May 22 09:26PM +0100 On 22/05/2015 21:18, Doug Mika wrote: > foo(int* x); > with a call: > foo(NULL); //but when would we ever use this? For all new C++11 code never use NULL, always use nullptr. /Flibble |
Victor Bazarov <v.bazarov@comcast.invalid>: May 22 04:32PM -0400 On 5/22/2015 4:18 PM, Doug Mika wrote: > When should I use NULL and when should I use nullptr? I've tried to find this on the net but I haven't been able to find anything definitive. The only thing I did find is that using nullptr anulls ambiguity when calling an overloaded function such as: > foo(int* x); > with a call: > foo(NULL); //but when would we ever use this? There is no ambiguity in that, only confusion. foo(NULL) will call the one with the 'int' argument, not the pointer. My recommendation is "always use 'nullptr' when you mean a pointer" and use 'NULL' only if using 'nullptr' is not an option (I haven't yet found any occasion where that would be so, though). Generally speaking, I think 'NULL' macro should be retired. V -- I do not respond to top-posted replies, please don't ask |
Luca Risolia <luca.risolia@linux-projects.org>: May 22 10:54PM +0200 Il 22/05/2015 22:32, Victor Bazarov ha scritto: >> foo(NULL); //but when would we ever use this? > There is no ambiguity in that, only confusion. foo(NULL) will call the > one with the 'int' argument, not the pointer. I don't think so. The above code does not compile on my C++ implementation because the overload is really ambiguous. |
Victor Bazarov <v.bazarov@comcast.invalid>: May 22 05:22PM -0400 On 5/22/2015 4:54 PM, Luca Risolia wrote: >> one with the 'int' argument, not the pointer. > I don't think so. The above code does not compile on my C++ > implementation because the overload is really ambiguous. Well, I see that g++ v4.8.3 (online) claims it ambiguous, but I can't find any place in the Standard to support that claim. Please quote the Standard if you know what makes the following code ill-formed: #include <iostream> void foo(int i) { std::cout << "foo(" << i << ")\n"; } void foo(int* pi) { std::cout << "foo ( pointer )\n"; } int main() { foo(NULL); } In my book the only possible definition of NULL macro (0) should make a call 'foo(NULL)' essentially 'foo(0)', which definitely does not make it ambiguous since '0' is an int first and only convertible to a pointer second. IOW, a null pointer constant (0) requires a standard conversion to become a pointer, which puts it *lower* AFA the overload resolution rank is concerned. I think those GNU folks want to be clever, and often overdo it. V -- I do not respond to top-posted replies, please don't ask |
Doug Mika <dougmmika@gmail.com>: May 22 01:14PM -0700 On Thursday, May 21, 2015 at 6:46:31 AM UTC-5, Victor Bazarov wrote: > V > -- > I do not respond to top-posted replies, please don't ask That's pretty neat :-) |
Victor Bazarov <v.bazarov@comcast.invalid>: May 22 12:46PM -0400 On 5/22/2015 11:17 AM, ghada glissa wrote: > global_var=Y; > } > } Great! So, you want it to be global, but you've probably heard or read somewhere that global data are A BAD IDEA(tm), and besides, in C++ every bit of data needs to be a member of some class (not true), so instead of declaring your 'global_var' as global (at the namespace level and extern as you would in C, for instance), you are looking for a way to pack it into a class, yet use it everywhere. Well, don't. Declare it outside of any class, give it an 'extern' specifier and live happily ever after. V -- I do not respond to top-posted replies, please don't ask |
Ian Collins <ian-news@hotmail.com>: May 23 07:45AM +1200 ghada glissa wrote: > I want a variable shared between many modules or classes. > I think "extern" did that, but i'm not sur about its semantic > So please help me. While you are reading the FAQ, also read up on how to correctly post to Usenet! -- Ian Collins |
Ian Collins <ian-news@hotmail.com>: May 23 07:42AM +1200 Juha Nieminen wrote: > annoying. You could of course ignore the indentation of namespaces, > but that's bad form (and also annoying with editors that autoindent). > There is, however, a small trick to avoid that. Namely: Google's coding standard has a do not indent namespaces rule and most editors I've seen can be configured to follow that rule. -- Ian Collins |
Paavo Helde <myfirstname@osa.pri.ee>: May 22 12:48AM -0500 Christopher Pisz <nospam@notanaddress.com> wrote in > The actual error message is too long for me to be > happy with copy pasting it. Why? Do you believe it would fasten the universe heat death or something? Cheers Paavo |
Juha Nieminen <nospam@thanks.invalid>: May 22 09:51AM > Trying to update my project to use a newer compiler. It started > complaining about my use of std::pow being ambiguous and having multiple > overloads to choose from. If both parameters are of type double, there should be no problem. Are both parameters of that type in your code? --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment