Keith Devens .com |
Sunday, March 14, 2010 | ![]() |
| Omit needless words. – William Strunk, Jr. (The Elements of Style) | ||
|
| ← CSS3 Selectors | OSX packaging groups join forces → |

Adam Langley (http://www.imperialviolet.org) wrote:
Keith (http://www.keithdevens.com/) wrote:
Yaaay! I figured it was something obvious. For some reason I thought strings were built in. Couple that with the fact that I'd declared the return types of functions as strings, and declared strings within functions, and the compiler didn't complain, and GCC worked, I didn't think for a second that that would be the problem.
Thanks Adam!
Jaak wrote:
GCC simply includes <string> as part of <iostream> inclusion and that's the reason it works in GCC.
Some people rely on it, despite it's not standarized.
That's one of many reasons why everyone should be using more standarized languages like C# or Java. There's simply less room to "innovate" for compiler/library designers there.
Unless you don't mind having 1 million #ifdefs in your code...
M. Bean wrote:
I was wondering how long it would take you to catch that. That was the first thing I thought of when you complained to me initially. "Strings aren't part of the standard types." Then I said "You just have to get used to how Microsoft does things" and left it at that. Yeah, I'm an asshole, sue me.
Keith (http://www.keithdevens.com/) wrote:
Bitch.
MattyT (http://sublimesoftware.blogspot.com) wrote:
Hang on, the standard is very clear on this issue. I haven't got the 'bible' here in front of me but I know this one from memory...iostream (or any component) may_or_may_not include string (or any other component). But, to be portable, a client must always #include the appropriate header files.
So, if you're using string you must #include it. The fact that gcc works is luck. It's not gcc's fault that you didn't include the right header, and nor should it produce an error or warning (though a warning would be nice it's very dear to determine when to deliver that warning).
Jaak, there is no reason to use any #ifdefs. Just include the files that you need and all will be well. Do NOT rely on the libraries including things for you!
I will concede that it's not easy to remember...but hey, one of C++'s principles is to 'trust the developer'.
Keith (http://keithdevens.com/) wrote:
It's not gcc's fault that you didn't include the right header, and nor should it produce an error or warning (though a warning would be nice it's very dear to determine when to deliver that warning).
Yeah, but we're talking about Visual Studio. It is Visual Studio's fault that it didn't complain when I declared things using the string class without it being defined anywhere.
Keith Gaughan (http://talideon.com/) wrote:
What sucks here isn't so much VS, or GCC, but C and C++, or more to the point, the preprocessor. There's no way of ensuring that includes are local to the file including it, ala Java's import keyword. Including it elsewhere would act as a check that you were using the right libararies, but would otherwise be ignored.
And on that point, wouldn't it be nice if there was a preprocessor directive that would include a file once and once only?
Does the preprocessor suck or what.
Thomas Minor wrote:
Look at '#pragma once' to get files included only once.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.111s.
(Used 8 db queries)
Maybe you should #include <string>?
Often helps when using strings
AGL