C++ Unions

  Рет қаралды 8,714

Creel

Creel

Күн бұрын

Пікірлер: 29
@grimvian
@grimvian 2 жыл бұрын
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-gw9ri
@LuciaSilva-gw9ri 4 жыл бұрын
I loved your explanation and your sense of humor.
@franzlyonheart4362
@franzlyonheart4362 2 жыл бұрын
31:06, didn't expect discussion of Double-D on the Creel. I approve of this message! :D
@manfredpseudowengorz
@manfredpseudowengorz 3 жыл бұрын
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,
@NeilRoy
@NeilRoy 7 жыл бұрын
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-z3c
@fanpeter-z3c 3 жыл бұрын
very clear ,sir , hope u can make more videos on c++
@majoro7251
@majoro7251 9 жыл бұрын
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?*!
@ninjalacoon
@ninjalacoon 7 жыл бұрын
Great stuff mate! Thanks a bundle.
@KansasFashion
@KansasFashion 6 жыл бұрын
Hell yeah man, love you!
@WhatsACreel
@WhatsACreel 6 жыл бұрын
Cheers mate! Back at ya!
@konstantinrebrov675
@konstantinrebrov675 6 жыл бұрын
Simply awesome lecture!
@jonatan6082
@jonatan6082 9 жыл бұрын
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.
@WhatsACreel
@WhatsACreel 9 жыл бұрын
+jonatan olsson Now that's clever!
@mattias3668
@mattias3668 4 жыл бұрын
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.
@WhatsACreel
@WhatsACreel 4 жыл бұрын
I might have meant natural alignment? Or it could just be a mistake. Anywho, cheers for watching :)
@narayananms620
@narayananms620 7 жыл бұрын
awesome video, appreciate it
@OssaGhalyoun
@OssaGhalyoun 8 жыл бұрын
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.
@sayyapureddisatish3467
@sayyapureddisatish3467 7 жыл бұрын
It's really nice
@fresayu1
@fresayu1 4 жыл бұрын
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!
@yosrimhamdi1435
@yosrimhamdi1435 7 жыл бұрын
A union is used to record multiple variable inside of it without wasting memory.
@muhamadabdulsamad2815
@muhamadabdulsamad2815 7 жыл бұрын
I can't understand~ ~ ~ ~
@Akatsuu
@Akatsuu 5 жыл бұрын
Anyone else triggered by his indentation and curly brace inconsistency?
@epickittylover489
@epickittylover489 9 жыл бұрын
YES IM THE FIRST! thankyou! i lo9ve you whats a creel!
@WhatsACreel
@WhatsACreel 9 жыл бұрын
+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!
@epickittylover489
@epickittylover489 9 жыл бұрын
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!
@majoro7251
@majoro7251 9 жыл бұрын
+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 :)
@epickittylover489
@epickittylover489 9 жыл бұрын
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
@majoro7251
@majoro7251 9 жыл бұрын
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!
C++ Function Templates
36:02
Creel
Рет қаралды 13 М.
C++ Bit Fields
30:01
Creel
Рет қаралды 15 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
C++ Function Pointers 1: Introduction
21:29
Creel
Рет қаралды 10 М.
C++ 11: Range Based For Loops
18:50
Creel
Рет қаралды 4,8 М.
C++ Tutorial 13: Passing by Reference vs Pointer
16:58
Creel
Рет қаралды 49 М.
C++ Tutorial 20: Inheritance Basics
19:04
Creel
Рет қаралды 8 М.
C++ 11 Lambda Functions
21:17
Creel
Рет қаралды 73 М.
C++ Tutorial 7: Functions
12:29
Creel
Рет қаралды 5 М.
Assembly Language Misconceptions
18:13
Creel
Рет қаралды 105 М.
Become a Malloc() Pro
6:58
thedoubleeguy
Рет қаралды 14 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН