RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

C/C++ complete references.

M

Myrrdin

Guest
C/C++ complete references.

the first book is for C++, while it is the fourth edition it is still very very useful...

C++: The Complete Reference, 4th Edition (Paperback)
by Herbert Schildt
ISBN: 0072226803
Comments: thick book, good for tossing at people, but seriously, it's great for those who just want strait forward explanations on things and also references... excellent for those who are wanting to go ahead and just learn conventions.

C: The Complete Reference, 4th Ed. (Paperback)
by Herbert Schildt
ISBN: 0072121246
Comments: same as above, but for C... couple this with the above and you got a solid understanding of C/C++

notes:
1) on both of these with how Micros**t does it's things they might nto work work 100% if your using C, but if you use Mingw32 you will be set.

2) these two books focus on general C/C++ programming but do not go into heavy details on standardized scripts... but it's still useful.
 

Zippy

Razor Creator
Believe me I know all things C/C++... If you wanna know something other than books, just ask :-P
 

arul

Sorceror
Zippy said:
Believe me I know all things C/C++... If you wanna know something other than books, just ask :-P
Ok, Zippy, I'm a bit confused with enums in C++.
Code:
#include <iostream>

using namespace std;

enum PeopleFlags { 
    None =      0x00,
    HasCar =    0x01,
    HasPet =    0x02,
    HasWife =   0x04,
    HasHouse =  0x08,
    HasGarden = 0x10
};

int main()
{
    PeopleFlags mask = (PeopleFlags)5;
    cout << mask;
    cin.get();
    return 0;
}
So, the problem is, why does it return 5, my presumption is it should return 8.
Btw. sorry for a small thread-hijack :-/
 

Sep102

Page
Essentially, enums are merely ints with a different type and that type is implicitly convertible to int but does not include a "conversion constructor" for int(which is why int i = None; works whereas PeopleFlags pf = 5; does not). Therefore it would make sense that you could assign any value that can fit in an int to an enum and have the enum hold that value, as it is only an abstracted int.

With that said, it makes sense that the conversion is applied between PeopleFlags and int is applied when you output it to stdout, as there is no operator << defined with right-hand parameter of PeopleFlags, and seeing as how all the conversion does is return the value held rather than the closest value defined in the enum (or some other such thing), 5 is output.

Also, the values in the enum's definition are just that, values assigned to that identifier, not the only values that an object with type of the enum can hold, however they are one of the only things that can be assigned to an object of that enum without a cast.



And, getting back to the thread's topic, if I were to recommend a core subset of books to read, I'd have to suggest

For C:
The C Programming Language by Brian W. Kerninghan and Dennis M. Ritchie

For C++:
The C++ Programming Language by Bjarne Stroustrup
The C++ Standard Library : A Tutorial and Reference by Nicolai M. Jusuttis
C++ Templates: The Complete Guide by Nicolai M. Josuttis and Daveed Vandevoorde
C++ Primer by Stanley B. Lippman, Josée Lajoie and Barbara E. Moo
Imperfect C++ by Matthew Wilson

And other than those, I'd also recommend most of the books from the C++ In-Depth series as well as the Effictive * line of books by Scott Meyers.

Other than that, practice, practice and more practice. Experience is the best teacher once you can grasp the basics.
 

arul

Sorceror
Nice, thanks for great explanation Sep, I grow on the enums in C#, so this was a little shock for me :)
 

Zippy

Razor Creator
Basically enums in C++ are just ints. Don't think of them as having any other special properties... they are just ints and they define constants. Depending on the compiler very little checking is done on enum types other than the checks for integers....

So something like

Code:
enum Color { Blue, Red };
enum Size { Big, Small };

Color mycolor = Big;

may work without any complaints on some compilers.

Unlike C#, C/C++ compilers vary widely about exactly how they do things, even between compilers which are also ANSI.
 

Sep102

Page
Zippy said:
may work without any complaints on some [C] compilers.

I agree with you with that addition to your statement, as most, if not all newer C++ compilers (at least ones that I know of) would not allow that to happen seeing as how C++ introduced new typing rules to give it much stronger typing that C has.

For example, enums (normally) have much more type information associated with them than they did in C, so there is a good chance that a C++ compiler (or C/C++ compiler compiling under C++) would not allow that statement at all or at the very least emit a warning that the two types are not exactly the same and it may not be what your intentions were.
 

xir

Wanderer
Exceptional C++ by Herb Sutter is a book for more advanced users of C++. It provides the does and don't of C++/STL, engineering designs and "safe" coding by presenting puzzles to the reader and then offers an in-dept solution and discussion of the problem/puzzle. It is very good reading.

The infamous GoF book, no developer should be without this in his repertoire. Design Patterns - Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

Another book you can't go without :- Modern C++ Design: Generic Programming and Design Patterns Applied By Andrei Alexandrescu

A copy of the real C++ standard in hardback if you have spare cash lying around is probably a good investment too. Although you can find drafts of the standard online, it is more a vanity purchase than something you'd really use. Just something to say "Yeah I got that."


UNIX Network Programming Volumes by Richard Stevens if you can afford it and are network inclined (although might be a bit dated)
Donald E. Knuth, The Art of Computer Programming (one of the classics) again very expense since it encompases loads of volumes.

Algorithms by Robert Sedgewick is a pretty good algorithms book too.


The one I'm currently reading which is also a good read.
Refactoring: Improving the Design of Existing Code by Martin Fowler.

For C, "The C programming language" - the famous "K&R" book so many C programmers swear by. Again really a vanity purchase but good if you want to learn C. Make sure to get the latest edition though or else you'll be programming from C like they did 20 years ago ;/


That's all I can think of the moment :>
 

wreckage

Wanderer
Sorious said:
WIN32API = easy :) MSDN tells all about it and how to use it with great explinations :)

Oh I agree completely very easy.. except when it doesn't behave right. Here's the problem I'm having:

I'm using Visual C++ Express
I've created a DLL for a global hook
I've tried this with both the GetMessage hook and the standard Mouse hook

In both cases I'm met with the same results. I'm simply trying to catch when someone right clicks on a forms minimize button. Naturally I'm watching for the WM_NCRBUTTONUP message to accomplish this. What happens is truly odd indeed. When the hooks are in place the hook doesn't trigger properly when I click the minimize button. If I click dead center or to the left of dead center on the minimze button with my right mouse button I get a system menu. If I click to the right of dead center over almost to the right border of the minimize button then my hook triggers properly but only far over to the right edge of the button. I've tested this with the maximize button and close button and they both function properly. Also if I use the left mouse button on my minimize button everything performs as expected. The only time this happens is in MY code and with the RIGHT MOUSE button.

Got any ideas? I can attach my projects if you need them.
 

Jeff

Lord
wreckage said:
Oh I agree completely very easy.. except when it doesn't behave right. Here's the problem I'm having:

I'm using Visual C++ Express
I've created a DLL for a global hook
I've tried this with both the GetMessage hook and the standard Mouse hook

In both cases I'm met with the same results. I'm simply trying to catch when someone right clicks on a forms minimize button. Naturally I'm watching for the WM_NCRBUTTONUP message to accomplish this. What happens is truly odd indeed. When the hooks are in place the hook doesn't trigger properly when I click the minimize button. If I click dead center or to the left of dead center on the minimze button with my right mouse button I get a system menu. If I click to the right of dead center over almost to the right border of the minimize button then my hook triggers properly but only far over to the right edge of the button. I've tested this with the maximize button and close button and they both function properly. Also if I use the left mouse button on my minimize button everything performs as expected. The only time this happens is in MY code and with the RIGHT MOUSE button.

Got any ideas? I can attach my projects if you need them.
I R C++ illiterate :(, i just know the WIN32API from C# :) You should start another thread asking for help here tho, im sure someone will come along who can help :)
 
Top