![]() |
|
|
|
|
1
8th November 21:20
External User
Posts: 1
|
There is a new book-ish like entity that is freely available on the web:
"Constructs of the C++ Programming Language" Found at: http://www.landrew.com The book is intended to serve as a light-weight reference for developers with modest experience in C++. This book will always be free and is intended to contribute to the social good, as corny as that may sound. If you think it might be useful to any community, please feel free to pass the reference along, link to it, blog it, etc. Ideally I would like it to easily be found via web search. Enjoy, Landrew [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
|
|
2
8th November 21:21
External User
Posts: 1
|
* Landrew:
[snip] Then don't redirect to the real page via Javascript, or via Javascript only. The page is at <url: http://www.landrew.com//cgi-bin/Via/Eval.pl>. I only looked at the "Exceptions" entry. I would recommend mentioning std::exception and std::runtime_error; not starting off with trowing an integer; using a constructor instead of filling in the members of a structure; deriving all exception classes (directly or indirectly) from std::exception; and not catching a class-type exception by value. Also, "Use ellipsis to catch any exception type. [...] Because the type of the exception is unknown, there is no way to examine its value." is incorrect: you can always rethrow and recatch that exception. -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
3
8th November 21:22
External User
Posts: 1
|
I looked at one page, Languages : C++ : Constructs : Arrays, pretty
much because it was the first in the alphabetical contents list, and I found several errors. "If there are not enough elements to fill the array, the trailing positions in the array are left uninitialized. int a[10] = { 1, 2, 4, 8, 16, 32 }; // elements 6 - 9 are uninitialized" This is wrong, in the snipped sited elements 6 through 9 inclusive are initialized to 0. "Arrays may be multidimensional. Use additional sets of square brackets to add dimensions. int a[3][4]; // 2-dimensional array" C++ does not have multidimensional arrays. What it does have is arrays of arrays (of arrays, ad infinitum). There is a difference, and it sometimes trips up programmers familiar with languages that do have true multidimensional arrays. "Pointers Arrays can be assigned directly to pointers. int a[10]; int *p = a; // p points to beginning of a No need to use the address operator '&' as with other variable types." This is at best misleading. The array itself is not assigned to a pointer. The name of the array is automatically converted to a pointer to its first element, which is assigned to the pointer. Furthermore it is just that "&a" is not required in the above example, it would be an error and would not compile. The type "&a" is not pointer to int, but pointer to array of 10 ints, which cannot be assigned to a pointer to int without a cast. "Arrays are always passed by reference to functions." In C++ you define a function that accepts a reference to an object to pass by reference. If you pass an array by name to a function, what you are actually passing, BY VALUE, is a pointer to the first element of the array, NOT any kind of reference. "There is no syntax to pass an array by value to a function, i.e. to pass a copy of the contents of the array." You can pass arrays by value, and return them, by making the array a member of a structure or class type. But once again, you don't pass an array by reference when you use its name in a call to a function that accepts a pointer to the element type of the array, you pass a pointer by value. A pointer is not a reference, a reference is not a pointer. I just looked at the second page, "builtin types": "Built-in Types There are four fundamental built-in types. Char A char is a single character. Int An int is a integer number. Float A float is a limited precision decimal number. Bool A bool is a boolean value of either true or false." No, no, no, no, no, just plain no. A comforming C++ representation is required to provide exactly 11 different integer types, no more and no less. Type char is one of those integer types, and while it can hold characters it can also hold numberic values that have nothing in particular to do with characters, so long as they are within its storage range. A conforming implementation must also provide exactly 3 floating point types. Then I looked at the detail page for 'char': "void main()" I'm afraid that you know too little of correct C++, and too much of what you think you know about C++ is mistaken, for me to consider recommending your "bookish entity" or tutorial or reference, whatever you consider it to be. Oops, spotted one more: "Dollar sign is allowed as well, but almost never used in practice." This is an extension to the language, which does not define this character in the required source character set. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
4
8th November 21:22
External User
Posts: 1
|
In article <41f23e2f.217070234@news.individual.net>, Alf P. Steinbach
<alfps@start.no> writes And I looked at the entry on built-in types and found something that I consider completely wrong. There are more than 4 built-in (fundamental types) in C++. For example, I do not accept that float, double and long double are all the same type, nor that float is the only built-in floating point type. This is just one of many places where the 'book' is, at best, a gross over-simplification. Actually it makes a good example of why even free books published electronically need to go through an editorial and review process. Without such a process there is no one who can write a correct technical book. -- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
5
8th November 21:22
External User
Posts: 1
|
* Francis Glassborow:
Uhm, yes, I've tried to do that with my attempted Correct C++ Tutorial, under development (it takes a lot of time to write this) at <url: http://home.no.net/dubjai/win32cpptut/html/> where I've solicited comments for each part from the [comp.lang.c++] community, and now also from [comp.lang.c++.moderated]... But even as I'm posting this message I know of a few Bludners. Belunders! -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
6
17th November 11:21
External User
Posts: 1
|
"Alf P. Steinbach" <alfps@start.no> schrieb im Newsbeitrag
news:41f3375a.280857578@news.individual.net... I have a note regarding 01.02 / 11: Your example says the output is: old=1, new=2 old=1, new=2 However, the program looks pretty much as undefined behavior to me. At least unspecified, but I strongly suppose it is much worse. And I am far from sure the comments after the code snippet make that clear (of course, assuming this is indeed UB :-). Thomas [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
7
17th November 11:21
External User
Posts: 1
|
alfps@start.no (Alf P. Steinbach) writes:
Here are a couple: " I made this tutorial because there doesn’t seem to be any other correct newbie tutorials on the web" "doesn't" should be "don't." Not a good way to start out a tutorial that emphasizes correctness ;-) "A C++ variable is a contiguous area of computer memory." This is a terrible way to explain what a variable is. First of all, it isn't neccessarily contiguous, even if you discount dynamically-allocated structures (only PODs have to be contiguous) and it should be presented as a high-level abstraction, not as a bucket of bits. A variable is a _name_ for some piece of program state. That may not be a perfect description, but it's way closer. Cheers, -- Dave Abrahams Boost Consulting www.boost-consulting.com [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
8
17th November 11:24
External User
Posts: 1
|
Actually, no. The quantity in this case is zero, which is formally
considered singular, not plural. The mismatch arises from using "tutorials" instead of "tutorial". The corrected sentence would be "I made this tutorial because there doesn't seem to be any other correct newbie tutorial on the web." Of course, there are other possibilities, such as replacing "made" with "wrote", using "...there seems to be no other...", etc. and Pardon me, but I don't believe even PODs really have to be contiguous, at least in the usual sense of the word. A POD struct can contain padding, rendering the members non-contiguous. I don't have the my copy of the C++ standard handy at the moment, but the wording of the C standard specifically differentiates between arrays, in which the items are required to be contiguous, and structs, in which the members are only required to be allocated in ascending order. Given that PODs were defined primarily for compatibility with C, it would be a major problem if the C++ standard really required them to be contiguous. IMO, "program state" might be a little _too_ abstract, at least initially. Personally I'd just call it a name that refers to a value, and wait until later to get as abstract as talking about "program state". -- Later, Jerry. The universe is a figment of its own imagination. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
9
17th November 11:24
External User
Posts: 1
|
Padding is part of the object, can be safely copied with memcpy and
is included in the sizeof( ) value. Furthermore, for PODs the sizeof value includes the entire state of the object. So IMO there is sufficient reason to treat PODs as "contiguous memory", even though the members themselves are not always contiguous. The difference with arrays is that the sizeof of an array is the sum of the sizeof of its members, while the sizeof of a struct can be larger than the sum of its (named) members. Regards, Michiel Salters [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|
10
18th November 13:22
External User
Posts: 1
|
* msalters:
Thank you all, Thomas, David, Jerry and Michael. I've now corrected the introductory sentence as per Jerry Coffin's suggestion (yes, I had a feeling there was something wrong!). I think I'll keep the description of a variable as a contigous area of memory, because it's short, not incorrect (AFAIK, but further comments welcome!), pedagogically sound, I think, building up from the concrete to the abstract, and essential to understanding the further discussion. The inner structure of a variable was intentionally not described. Of course that's sort of lying by omission when std::string is introduced, but I think that's pedagogically sound: somewhere later I can ask the question of how a string can be in a contigous area of memory, and the answer no, in practice it's not, but the variable that you deal with is -- good for introducing dynamic allocation. Regarding Thomas Mang's point about UB in the example 01.02/11, I'm not sure how to deal with that, and I'm not even sure whether it _is_ UB (ironic since part of the point of 01.02/11 is to warn against UB). Suggestions? -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|