I'm learning C++ and have done that for 18 months. In my opinion the best teachers had not forgotten how the state of a learners mind is. Despite Creel's very high level of data knowledge, he is a rare instructor, who understand how to teach with no background music and adds! THANK YOU! You are the only one, I came across who explains what they can used for and in the same time explains how unions works. I really like the way you take examples from a document and test with example code.
@LuciaSilva-gw9ri4 жыл бұрын
I loved your explanation and your sense of humor.
@franzlyonheart43622 жыл бұрын
31:06, didn't expect discussion of Double-D on the Creel. I approve of this message! :D
@manfredpseudowengorz3 жыл бұрын
25:00 order of the struct member is preserved in the order of the designated memory areas. whether the structs were declared as presented, it would be short a and char c to occupy the first 8 bytes of the memory reserved for the union,
@NeilRoy7 жыл бұрын
One use I seen for union was like the following; struct vector4 { union { struct { char r, g, b, a; } struct { char x, y, w, h; } } } ...something like that. You could create a 4d vector and use r, g, b, a or x, y, w, h... and I believe there were more in there, so it gave you a choice of how to access them depending on your use. It would only use four bytes of memory no matter which you used and you can easily add on any other four characters you can think of to this without using up more memory. I think unions are commonly used in event structs as well. I also seen some really good examples recently where someone used unions in procedural programming in order to get away from object orientated programming. It was quite interesting. Myself, I code a lot in pure C (using the 2011 standard and the GNU C compiler) and unions as well as bitfields you showed in another video are all part of C and not C++ specific, so you can do a lot more in C with them that one might not consider you could do in C without classes.
@fanpeter-z3c3 жыл бұрын
very clear ,sir , hope u can make more videos on c++
@majoro72519 жыл бұрын
I think unions are VERY useful when it comes to using a certain struct extensively throughout a program. E.g. programs that are heavily dependent on a messaging system which uses structs. Thanks for the awesome video, *What's a Creel?*!
@ninjalacoon7 жыл бұрын
Great stuff mate! Thanks a bundle.
@KansasFashion6 жыл бұрын
Hell yeah man, love you!
@WhatsACreel6 жыл бұрын
Cheers mate! Back at ya!
@konstantinrebrov6756 жыл бұрын
Simply awesome lecture!
@jonatan60829 жыл бұрын
In a game i'm currently working with, we are using C++/LUA, and we came across a problem where we would have to send data from actors to other actors wich holds thier own seperate lua state. I made a super silly event system that could send pod data to another script. And what it really does is just reading the arguments from lua into C++, stores them in an array of unions wich can hold the specified pod data. Later we just send those arguments to the script that will recieve the event. That's one of the rare times i've used unions.
@WhatsACreel9 жыл бұрын
+jonatan olsson Now that's clever!
@mattias36684 жыл бұрын
There are other endians than big and little, although my will probably not encounter them. 26:40 assumes that double as an alignment of at least the size of short. 26:50 assumes that double as an alignment of its size. Types, even intrinsic ones, can have a different alignment than its size. Also the sizes of the types depend on the platform. Only the minimum sizes are guaranteed: sizeof(char)≥1, sizeof(short)≥2, sizeof(int)≥2, sizeof(long)≥4, sizeof(long long)≥8. Unions are great, especially for creating classes in C. There are also cases where you want to use unions because casting may break aliasing rules.
@WhatsACreel4 жыл бұрын
I might have meant natural alignment? Or it could just be a mistake. Anywho, cheers for watching :)
@narayananms6207 жыл бұрын
awesome video, appreciate it
@OssaGhalyoun8 жыл бұрын
How on earth do you get VC to print to a cmd window, my VC express 2016 never does, it creates weird window instead of cmd even on blank application project.
@sayyapureddisatish34677 жыл бұрын
It's really nice
@fresayu14 жыл бұрын
Hi! I'm new in c++, and I still doesn't understand why we cannot use a std::string into a union? Each time I use a std::string into a union, it always said : use of delete function. Thank you!
@yosrimhamdi14357 жыл бұрын
A union is used to record multiple variable inside of it without wasting memory.
@muhamadabdulsamad28157 жыл бұрын
I can't understand~ ~ ~ ~
@Akatsuu5 жыл бұрын
Anyone else triggered by his indentation and curly brace inconsistency?
@epickittylover4899 жыл бұрын
YES IM THE FIRST! thankyou! i lo9ve you whats a creel!
@WhatsACreel9 жыл бұрын
+epic_kitty_lover489 What happened to my reply? I replied, but it vanished...? Anywho, I want to say congrats for being first, and your channel is hilarious!
@epickittylover4899 жыл бұрын
thankyou! i didnt think you were gonna watch my vids, im not actually as old as i sound, im 15, and i am a HUGE fan of you, i learnt c++ from you only and now i know it! so i owe a lot to you, you tutorials are awsome!
@majoro72519 жыл бұрын
+epic_kitty_lover489 that's bad@ss! wish I started when I was your age. Keep on, and learn some assembly. Read some books like Windows System Programming and check out handmade hero, as well as What's A Creel? awesome videos. All the best :)
@epickittylover4899 жыл бұрын
yeah ive learnt html + css, c# and c++ and a tad of php since i started watching his videos, i defs gonna be a programmer when i grow up, i just enjoy doing it so much
@majoro72519 жыл бұрын
Big endian and little endian problem, is a little bit of a nightmare... *suddenly, windows 8/10 tiled start menu pops up* now that 's the real nightmare!