Updates: Tyler on PowerHacking CSS to cutestrap your app in this latest episode!

Topic 3 - while loops iteration practice, portable types, conditions


  • while or for, both ways. Avoiding do-while.
  • The fixed size basic types
    • unsigned vs. uint32_t
    • int32_t, uint8_t, etc
  • conditions, braces: mostly on style
  • bit and byte counting on types, sizeof review


everybody how are all of you uh
sorry tyler i just saw that super last
minute and
i should have rolled it right before
that um
you know what you know what i i just
you're you're so great
that this is this is tyler by the way uh
i'm not gonna say more about tyler and
his awesomeness but
uh just for tyler that's for you tyler
um it's not a natural 20 though i have
to confess
i just totally positioned it um so hello
everybody uh we have
jessie on the line it's the enceladus
saurus did i say it right
yeah you got it oh my god okay sweet
um and she's here because we're gonna be
learning c she's had enough of this
whole managed types thing from python
and all that silliness we
we're gonna get down and dirty with
memory and we're going to manage it
ourselves because we
we do that we're
we're just going to torture ourselves no
no no okay and
hello strophium how are you uh and
have fun yes um i i'm sure she's gonna
need it because we're gonna get into
some fun stuff so
uh let me show you kind of what we have
in store for you tonight
so um as those of you who were following
along before we already went through
topics one and two
um and i am by the way just evolving
this this is from the website coding
with some guy
sorry about the site tyler by the way um
just so you know jesse tyler is the most
guru of css like in existence of
person kind oh wow
so that's that's quite the endorsement
i have only the greatest words to say
the next one yes
that one stat is like through the roof
so it is
visual it is like physical pain for him
to look at my web pages
and i'm sorry i just
i threw it together really fast one day
but anyway i spent a lot more time
focused on what's on that page rather
than how it looks so
i'll take small comfort in that but it
is a work in progress so i'm
just gonna keep uh updating this as we
sort of go along and realize
uh what what is helpful to a programmer
coming from
python which is where jesse does most of
her astrophysics
um and oh that's okay tyler says content
is king so
we're okay i guess i guess that's all
right endorsement wise
all right so um for tonight we're gonna
be getting into
uh so we're the enceladus source and i
are going to be experimenting with a new
we're going to go hardcore on the
learning in the first
hour and uh then we're going to go as as
questions and topics come up we're going
to go we're just i'm just going to write
them down
over here on my trusty notepad
which i have labeled as part two topics
and scotch
so um that's uh
we'll we'll get into the all sorts of
random stuff about uh computers
uh in that segment so for right now
we're gonna focus on topic three
which is really about the other loops
and we're gonna get into some of the
fixed sizes because
jessie needs to manage the memory
herself and
i think once she's done enough of that
she's going to realize how great python
i already think python's amazing
yes just as a tangent corner strophium
says very nice
um and yeah we're all about that uh
we're just uh
i i confessed to her that i would feel
really terrible if
i was teaching her c and she walked away
not knowing c because we had too much
fun talking about
two's compliments and all the other base
20 numbering systems and all the other
things that we're
getting into so so why not both right
i mean that's the answer so i've already
got the glove on we're ready to draw
and uh i think with that
let's get going so let's switch over to
our editor here
which has been evolving a little bit i
just pushed
almost the most recent version of the
code we're in c mode
tonight uh tyler in particular you're
gonna love this because
this allows you to pair program group
program over the internet
uh with uh i have pluggable
authentication i'm not gonna go too much
into this but
basically i call this the multi-user pad
and uh
we've got our whiteboard coming through
up here so that jesse can see it in real
time her audio audio's in in real time
there's a little bit of lag on stream so
and what's up fafi hello
uh so uh we're in c-mode
foffy unlike earlier today we're not
doing our python or javascript modes
and uh yeah we have a new feature that
jesse just discovered
in warm up which is
errors look at this
beautiful error so big improvement from
last week so we can actually see errors
when we uh when we get around to that so
before we can type errors let's do a
little bit of theory so
um i am going to switch over to
full-on mode uh you can feel free to
watch wherever you want jesse
all right so today we're going to be
talking about what are we talking about
we're going to be taught let's go red
in honor of tyler who's here so we're
going to talk about while loops
and we already know about the three part
three part four not four
and we're gonna talk about the do while
and why you should never use it again
so that's kind of our most important
thing to learn from there
in the second part we're going to talk
about fixed sizes
and you know because that's the second
part i'm going to just
green that up so we're going to talk
about fixed size
portable types
and this is going to be important
because so far we've been using kind of
the classic
uh styles of defining how we want to
deal with memory so
we're gonna we're gonna move into the
new age and
the new age is all about
in c we're gonna be doing the new age
meaning c89 or the 1989 standard of c
which is brand spanking new there's
actually there's a c11
and you know we're going to be kind of
using that too and some other fun stuff
all right so without further ado let's
get back to our redness
so what do we do with a while loop well
it's not that different from the four
right so in our in our three part
four unlike in python we have sort of
you know our initial case i should
actually use the labels that
that jessie likes to use um she calls
start i'm gonna rename this middle one
to during
which is sort of like the end or rather
inverse of it not the end
and um the iteration the iterate case so
this is
um and just to review this is basically
how we're going to get started with our
loop you know whatever we have to set up
in the beginning
this is how we tell if we should keep
going each time we go through the loop
if this is true then we're going to keep
going otherwise we're going to stop
and this is what we're going to do each
time through the loop um
so in our regular example in c this
usually looks something like four
in i equals zero
so we define an integer zero we say as
long as i is less than
five and take i i'll write it out the
boring way
and take the old value of i and add 1 to
it and store that in the new value of i
cool and then we use braces because this
c and we have to specify blocks this way
we don't use we don't count on
okay and uh nathaniel is mentioning we
might as well go
c18 wow this is let's get some pretty
crazy stuff here this there's all this
newfangled see i don't know what
nathaniel's talking about here
um so oh yeah that's right we were doing
c99 before i'm so sorry i don't want to
be talking about c89 i want to be
talking about c99
okay we should probably pick a different
variable other than i because
i don't know if anyone else is maybe i
mean maybe other people are having less
issue but when it's all written out like
i'm having trouble telling the
difference between the eyes and the
thank you okay perfect there we go
i don't know how much my handwriting is
actually that j looks exactly like a
that one at least it's white it's just a
ground up rewrite this is z
and z and z and z there you go that that
doesn't look like anything else
okay and what's up loaf bone how are you
um so just use capital i hand no
nightshade dude no trolling this early
okay so this was our i don't know enough
to be trolled yet
don't don't troll her yet let her
let her let her get the crack first okay
okay all right so that's enough of the
three part four
we'll we can do a little bit of uh
reminders on that if we need to um so
tonight we're going to be talking about
the while let's start off with while so
my least favorite loop while is really
now it's kind of funny in c because in c
you're allowed to leave any of these
three parts so we had like what do you
call it start
middle and
that's totally wrong actually isn't it
so this was start
during and the iteration so
any of these are actually optional in c
so if i want to build a loop that runs
forever i can just go like this
actually i could say four
and put nothing in all of those moments
and this is just forever
misusing like the for loop is like one
of the greatest things that you get to
do in c
but it makes the most unreadable code so
this is this is one way
what's a more proper way to do it it's
like you know
we could just say like while and
because i'm not really using any of
these other parts so this is a little
bit naughty use of the for loop but
anyway with while all i have is just
the condition and the condition
corresponds to the during
again so that's the same as in python
right so you have like your your forever
loop and python looks something like
wild true right
yeah all right well that's fine
and the c version of that is you can say
wow one
because there's no true and false in c
because that type doesn't exist wait
booleans don't exist
there's no um there's no booleans
in in c so what
yeah we went over all the data types the
other day
is something and we didn't go over that
so i just thought we hadn't got float
for floating point
double for double i mean there's the
long version of the integer
and how do you no no no no no no wait
wait wait
because i when we were warming up i used
a double equal sign somewhere oh yeah
there's definitely
boolean arithmetic like there's there's
all that there's double
he's not a bullied type there's greater
than or equals there's less than or
equal there's all there's all this stuff
but it's sort of for the for the
javascript people in here it's kind of
so it it it ends up being um
anything that evaluates to zero
is false and anything that evaluates
not to zero is true
and this is kind of a very c
world so if you want to be
naughty you can use you can use anything
here for true you could say like you
if negative one and you know that'll
so oh hey what's up drop fair
whoa you know morse code
what hold on it's been it's been years
since i played nancy
that's the last time i learned morse
code was i learned fancy drew
i i don't think i could faffy there's no
triple equals in c
so wait no don't do that
ah i actually know morse code but that's
for reasons that we're going to get into
when i
hooked up the telegraph key to netflix
all right so back to our while let's
let's stick to this so
how much sense does this make to you i
mean based on your python experience i'm
guessing you've used wiles before
unfortunately okay so we we can do our
forever loop if we do that i don't
there's no way that you can stop your
program so i
don't recommend you write an infinite
loop tonight yes
that's that i am aware of uh dropbear
that is correct
0 is equal to false and anything else is
true yes
um except in some functions where
they return zero meaning true and that's
but there were there were fights in the
standard but yes generally speaking when
you're talking about conditionality in
the language then
yes um okay so let's just do
what do we do with our while loop well
we i can
write w so
so it's while something is true okay
and we just learned that true is kind of
a little bit loose
loosey-goosey and insane but um so while
something is true
do some code and you know
have fun and do whatever you know do
the thing and this will work
like this will just keep on running this
as long as this is the case
so our only way to kind of control this
is to
sort of be careful about whatever this
condition is if if we do write something
like this then
you have no way to stop it and i should
really make a note that you're gonna
need a
way to stop that
stop i mean that sounds just like python
yeah because this this this program
doesn't do that um
oh hey you got a lot of people dropping
by tonight okay
so um great we're gonna use a while loop
pretty much like a four for for now
we're not gonna spend too much time
with wiles but i can tell you that like
in cases where
it's less about counting while is
usually more useful
like for example while you know
stuff in the file
parts file so
this this would be the kind of case
where you'd want to use a wild naturally
make sense that makes sense yeah yeah of
course um
all right and then i'm briefly going to
mention the do while
which is just something terrible and
it was not brought over to python i
which is very similar to the while
because the while goes at the end
but you also crossed that out so i have
a note saying don't do that
why don't we like do wiles okay do while
it was originally thought to be kind of
a good idea it ended up
being pretty nasty because
it ends up hurting reasoning but let me
let me before i get on its case let me
tell you what it does
do while just in case this is more
important if you run into it in somebody
else's c code rather than you should
ever be running
writing it yourself um do while
basically it's the same thing as a while
loop but we've inverted the position of
the while on purpose because
basically we're saying do this stuff in
here first
and then evaluate the condition
okay so it's it's kind of like
a while but you want to make sure that
it runs at least once
um so it you know again
valid c syntax you're not it's not a
very commonly used
operator and due to that due to the fact
that like not a lot of programmers are
comfortable using it a lot of bugs have
kind of crept into a lot of code because
of the use of the do while so
it's one of those things where it's like
it sounds really neat and it's a lot of
fun to use it a couple times and then
you're going to kind of realize like
like you're going to see it around and
you're like ah that's not really
commonly used but yes it does get some
use i mean it's
um loaf bone is the audio having issues
i mean
is it like both of us kind of crackling
i don't know i'm having some issues
every once in a while you cut out a
little bit
but um it's not super super bad
okay um i just yeah nathaniel kind of
summed it up it's it's been
basically cut from pretty much every
other language
it doesn't really do anything that you
do with a while loop anyway right i mean
like so all you have to do is really
just kind of play with your
condition or you could do it with kind
of a for loop so it ended up just being
kind of language tax
in that we had to support another
construct but um
it doesn't really functionally add
anything that while or four doesn't do
with about the same
like brevity you know it's not like it
saves a ton of time versus using like a
while or something
okay that makes sense yeah uh
so dropbear is asking hey have you gone
configuring a compiler environment um
dropair no
but what i did do is uh i made this all
so that's actually part of why i built
this tool in the first place
because that's a hard problem
so um it's one of those things like to
get this c
compiler set up and get everything like
kind of working it's like
some version of a c compiler is usually
running on most systems these days but
like getting it to be stable and a
certain standard and everything else
like that's that's actually kind of a
lot of work so
i figured for um like
you know kind of people that are new to
a given topic
that's probably not a great set of steps
i think it's better to kind of get in
the language and that's part of why i
made this environment
look the way that it does so basically
this this is plugged straight into the
compiler environment on the back end
and you know we get our output over here
so we don't have to worry about tool
chains and we don't have to worry about
all the other stuff that goes with
setting that up
but i can tell you that if you're
curious i do set the environment
up for you if you pull the project so
you can go into um this is on
github coding with some
guy and if you go into this repo that
i've made up for the multi-user pad
there's this script in here that'll kind
of do all the work for you if you happen
to be running on an ubuntu like system
uh that's that's a huge task that you
just mentioned like across every
operating system and different tool
chain versions and everything else and
i'm not even beginning to start
talking about cross compiling but anyway
let's not scare jesse
boy this does have my favorite line of
code in it i can tell you because it has
the i
am crazy flag which you have to set to
so you have to be crazy to run this
thing and i'm not
i think that sets the right expectation
okay so
great so while loops
and do while loops and for loops all
make sense
yes i think so okay mary jo stabler
what's up
how are you all right so we got loaf
bone we got
um although swift has a do well oh i
guess some places did bring it around
says and mary jo stablers good good how
are you i think we're good we're just
getting into our
groove here all right so let me
yeah let's just let's just run ahead for
the other part of the
the whiteboard stuff so that we can get
all that out of the way
all right um
no i don't want to do that obs don't be
a bad obs
okay so let me uh all right here we go
second part is really about fixed types
and you know i think a pretty good way
to guarantee that you forget
everything that i just told you is that
i should just go into this right now so
let's let's not do that
let's do a little let's do a little
practice okay so
um great your basic
while loop uh has a form
similar to kind of like what you were
doing with your for loop so
your your syntax actually i should let
you type what does your for
pseudo code look like
hands off it's not me it's not a macro
yes and we get our block yes
four score and seven yeah merry
christmas having some fun
okay um and yes by the way nightshade do
but i'm not
i'm being careful on that one so
okay um while looks more like
yeah exactly okay this is part of why i
was trying to avoid the word while and i
was trying to call it like during but
um but yes it is very much the while
like truthfulness
okay and yes while my guitar gently
weaves great song by the way
um i like
i like where where he went with that i
didn't know setting up correct flag is
very complicated according to you or am
i missing something here um
prayag no it's um
tool chains let's get into that in the
discussion section
i'll i'll throw that on the list so
okay um so in the meantime
let's uh so just to warm up
let's print out the first five numbers
using a for loop okay
nice slow phone i i i'm guessing that's
probably related to the instability
twitch was having earlier with the
reflection network and the way they were
moving the streams around
dad don't where did you get this habit i
you taught me that i taught you
why no i don't want a pre-increment
because i don't want it to
i oh well you do want me to start with
zero one uh
mary jo stabler we're doing c by the way
strophium's actually writing out the
longer answer but
bugs are actually the reason that i'm
things changed across standards
because if we increment before won't it
go to
one at the start of the loop let's see
what gets
printed let's find out the answer to
your question
we don't have to guess we have a
this is like i told tien on stream the
other day she's like
how do i know the answer to this and i
was like you know it's like that scene
in harry potter like you're a wizard
you have a wand you have a compiler
you can do anything you want with this
thing build all the software in the
you have something better
okay um so it ended up working
the way you expected or not no
no yeah it's kind of don't don't worry
about it too much just just let's get in
the habit of using
pre-increment we'll get into reasons
later okay
um in this case it doesn't really matter
anymore in modern
modern standards um mary jo stapler
that's that's a longer
all right i think i think chat's hungry
for that one so we'll talk about pre and
post increment
in the discussion part
okay so yeah
great now how do we get the first five
looking good yeah
that's kind of awesome all right so we
remember how to do some basic for loop
great now how do we do it with a while
i'm going to leave the for loop up just
for a second absolutely fine
uh strophium is correct by the way um
and in particular a lot of constructs
that come in c plus plus it does matter
a lot more but let's um i'm going to
kind of punt on that for a moment so
i'm just going to add in a new line so
that you don't trip yourself up with
output okay now
i did tell you that we normally scope
int in c but that's because we have an
in sorry in in the for loop right so so
in the for loop we actually get to like
set our initial values
this is not good in a while loop however
because we can't really initialize it
it's not an initializer
yeah there's no initializer in a while
so you got to get rid of that int as
oh yeah thank you
yeah look at that it works
pretty solid uh and you've managed not
to do an infinite loop with it which
i'm really impressed with because let's
get that kill command ready
okay um so
yes this system by the way if you look
in the code repository does not have a
lot of limit
calculations so yeah containers let the
container do it right
no let's just be careful so okay that's
copy this format how do you think you do
the same thing with a do while like say
you want to run it once
oh um so in this case
notes so do this and then
the vial comes up here but then this
so it runs first before it iterates so
i'm just going to hide your earlier
output so that we only see
one of these and i'm going to give you a
little clearer here
so if it runs once before
what's i think iteration zero
until the end of the iteration then it
becomes one
so it's zero when it goes put care yeah
and then it runs the next line
which well then adds one
so it's one at line 19 right yes
yeah and then what happens
well so then
then it hits wow yeah so i mean
functionally for this loop
right i'm sorry you cut out there can
you say that again oh yeah uh
functionally for this loop it will be
the same
yeah go ahead run it
bye drop bear thanks for stopping by
dropbear is awesome um yes okay so it
okay and i'm also gonna copy this
so i think i think just because of the
structure of this it makes sense that it
it would kind of evaluate the same um
but i can see how you would get into
like for for certain loops i can see how
you in trouble
with the fact that it evaluates first
yeah and sometimes this is done
there's different reasons why the
language authors originally wanted to
put this there i mean
the general thought was that sometimes
you want to write you want to run a loop
no matter what
even if something is false it's like so
even if you only want to do it once
it'll go but in the case of like the
while you might
not ever run it you know you might do
right you know something false
and i use while a lot with like scoring
and like
almost yeah so i i kind of get what
you're saying where like
you might always want to run a loop but
there's going to be cases where
you want it to almost you want it to be
a conditional it's almost like if then
but you don't want to code out all of
the different ifs
so while is while is like a neater way
to do it
yep yeah that's one way um also
sterfian's totally right
i just saw moshi moshi's comment um i i
uh i actually didn't change anything on
my end
um i think i'm just guessing that it's
probably related to the instability that
from twitch and twitch being out earlier
it seems like uh last uh sorry
loaf bone uh ran into this problem
earlier and was lucky when on a
reconnect that
i got a different server um so strophe
i'm saying with oop
with object-oriented programming i
shouldn't say oop it could be
semantically necessary
object performance function could be the
thing that's generating the
determination condition yes
it's true that this actually does come
up more in c
plus than it does in c but for for
straight c it's
it's relatively uncommon to see it um
it'll occasionally happen with file
semantics but generally speaking
anything that you can write in a while
you can also write in a do while
the only real exception is whether or
not it's going to run this thing every
even if the condition is false like so
in the case i'm sorry i'm selecting
lines she can't see selections
i'm i'm walking i'm watching streams yes
so the body here would be executed no
matter what at least once
in the case the do while but in the case
of the while
if the condition's false it'll never be
executed you could just
copy it and put it up here if you wanted
the spacing's really going to drive
strophium nuts so just to
kind of fix that um so that strophium's
happy this is kind of more standard
so okay um
so those kind of make sense yeah i know
it's a
quick version of it but i mean i'm kind
of assuming like the python background
and you know we're just sort of
translating that stuff into c
okay yeah it really it really does
especially with the loops like
i honestly i know before but i love the
the sort of three argument format yes
i like that so much it's illicit and
it's just all right
there and it's so nice and python needs
to be copied
they are strongly against it in python
you know what i'm i love python but
that's like python's wrong
okay we sorted out okie gone as well
um it's funny how like the spacing was
throwing them off and you're a python
programmer normally so
my how the python fell fast from you
you're like i was facing i could do
whatever and see i mean i could
i could just be like oh what was the
spacing i don't know
where oh was it back all the way there
no no you had it um
it was one off
so it's really hard to see in this
editor for me but
don't worry yeah yeah i don't have any
there's no visual indicators about
like that but um anyway um
we also don't in c c tends to be a lot
more compact
so typically this will be written more
like this
you know related blocks tend to be all
together like they they typically don't
get much spacing
um python like python specifies that
there should be spacing like
it's one of the peps yeah i find that
easier to read especially if i'm
learning something new just have it kind
of spaced out but
that's just me dystrophiam's comment c
programmers like to make their code look
as complicated as possible
i would say that that's not entirely
true compared to pearl programmers
but i had to do c
because i had too wild because bcpl had
well i've learned i've learned already
my sort of programming gurus that
the hardest thing is not to make your
code look difficult it's to make your
code extremely readable
ah yeah so very pythonic stance by the
see people do not have that stance in
by the way well i like it i like that
it's less about looking as complicated
as possible and it's more about
come on we're writing c we got to make
it look complicated i agree with
all right it's uh so we'll agree to
no i'm i'm trolling i actually do agree
with you
okay um great let's get
to oh totally
let's let's get to the other part of the
so fix types
what are fixed types what types do we
know about right now
um int care and strings well strings as
sort of like strings of characters i
don't know if that's like an explicit
i'm going to give you that's kind of
what we know a lime green here and we've
talked about other stuff like
longs and shorts or something what was
the double skin care and what
string ah there's no string type
yeah so that's what i said is i'm not
sure if it's actually a typo just a
string of characters
but yes it's this this isn't c
plus plus we don't get we don't get
string as a type
okay um so right
you and then you started mentioning some
of the other types that we have done
less with like
floats and you know double the size of a
float because double
and double the size of an integer
because long
now these are all signed types
yes as we kind of digressed in
the second episode it doesn't really
make a lot of sense to talk about
care but care on its own is assigned
i should say as well you you can have an
unsigned care
i mean it's it's valid you can slap
unsigned basically in front of any of
and you'll get their unsigned
counterparts so you could say
unsigned int
unsigned long
whatever that that all works but
like i told you and warned you very
quickly before this wasn't really a
standard size in a lot of the original
so um things
that uh that created a lot of trouble
and partially because like the original
standard on an int
was convenient
so this was something that was a
convenient size for
an integer on your platform and that was
mainly because the standards were not
getting specific about like what
how many bits there were in a bite you
know so like back in the day you know
you might say something like
you know a character how big was a bite
well the answer we typically whip out is
it's eight bits
but that's not true on some platforms
because sometimes a byte is 12 bits
or maybe you have a nibble platform
where it's four bits or you might be
dealing on an 18-bit
architecture because somebody was really
just having a little too much sauce i
don't want to get into the reasons
okay but the fact is this was kind of
non-standard the standards committees
all moved away from
using this term at all and they just
started referring to octets
in general and that that was very
clearly eight
so that had a really nice name but c was
already created as a language and
when you started saying like okay how
big are these different types we
very quickly touched on an operator the
the other class do you remember what it
was to see how big something was
oh shoot um good job
shoot i tried
i tried so hard it was like guest size
or thing it's very close
um it's what is the size of
this there we go okay yeah
okay and we can specify either a type
directly as a cast which is we just put
it in parentheses
or we could just specify the size of
a variable like z
so if i defined z
to be an integer and then i do a size of
that's fine okay but the parentheses are
not required
in this case because sizeof is actually
an operator in the language it's not
a function no matter how much we want to
make it a function
okay um oh and sorry i just
realized i missed a bunch of things in
chat um
yes panos i agree with you uh
she's also a streamer so she has a
streamer voice
uh c doesn't have streams you have care
star yes strophium got that and not
gonna comment got documented somehow yes
who needs indents just need less lines
of code mary is
right think about punch cards and the
other ways that you could write this
back in the day
so oh lord and yes uh okie gone
quoted a famous gem in this space which
is it was hard to write it it should be
hard to read it
oh gosh sorry that got old man voice
um and and yes by the way nathaniel like
i'm not talking too much about the newer
standards because that's not going to be
a lot of the c
code that she sees um most most c code
is going to be pretty classic
okay so this back to back to brass tacks
we can look at the size of any of these
things directly in the language
and int ended up later on getting
standardized as 32 bits
which is the same as 4 characters
and a care was defined as one byte
which was problematic
and a short was defined as somewhere in
between these so if i built like
a size scale of all of these things long
was sort of the big one
i'm not going to talk about the the ieee
types which were added later
but along was sort of the big one and
you know you had sort of at the other
end you had like a care
there's no notion of a bit or a bite
like a
there's there's no bit type but there
are some unary
there's bit fields and stuff that we get
into a little bit later um
and everything is sort of on the
spectrum between these two
okay so int most of the time
is the same size as long except when it
and okay short is
most of the time twice the size of care
but except when that one was that sort
of fell
out of use you know this this was sort
of more in the era of like 16-bit
and it it was it was it never got as
much love as the other types
int used to be the size of a short and
some older compilers
and but then they realized that's kind
of crazy and then they made it the size
of a long
until that was all fine when we were in
the 32-bit world but
computers these days how many bits do
they have
64. you got it just look up like
most of them are 64 now so what do we do
well we could just make this long 64
bits and then
that's fine intel just sort of stay 32
bits sometimes except on other compilers
where it'll occasionally follow the
64-bit thing
and in over here well it's pretty much
always going over there and shorts
sometimes is just
short and then oh but we need to have
unicode because what do you do with
characters that are from like
international standards they don't fit
into eight bits anymore so
this this whole character thing is kind
of crazy so then we get the wide
character type and then we get all sorts
of other stuff that starts to happen so
i'm not going to get into this this led
to insanity
okay and that was
bad so a lot of programmers
got into some crazy stuff to try to work
all of this like craziness and so one of
the things that they would start to do
is they would start to say okay
my long and they would define their own
is really 32 bits
and i don't care what platform you run
it on my long
is always 32 bits this was a fixed size
this turned out to be because they said
it yeah they said it yeah okay
like so they'd start doing all sorts of
crazy tricks which i'm not i'm going to
show you that later when we get into
those but c is it turns out from
that who studied a lot of static
analysis stuff in c
that c is not a language c is very
loosely a language because
everywhere that c exists it's pretty
much off standard in some way by using
the standards
so that that's going to start a fight so
i'm not going to get into it but
we can we can get into that later
um oh and hello last miles how are you
doing uh
i'm i'm not getting into utf-8 for right
but um that's actually last miles is
bringing up kind of the solution that
was sort of
sane to all of this which was
you know what do we do with characters
when we want to start having global
encoding well there was originally this
notion of a wide
character which was kind of non-standard
and it made it into a few of the specs
it there wasn't a lot of agreement on
like you know what those characters were
mapped to and then
they said well we could just make
everything really really big you know to
fit like every possible character
and that that kind of got crazy so then
they said all right look let's talk
the glyph itself which is like
some particular character like so you
know this could be
oh right we were talking about this last
week with with how you kind of
incorporate all of the different
like so here's the dragon in very fast
scroll so this character let's see
this is a glyph um it's not
a it doesn't specify a particular
encoding it's just that this character
is dragon
pretty much all the time it's written in
traditional style here so
we can worry about what character that
is which is talking about
glyphs and then we can worry about how
we're going to encode that
and that really kind of gets into what
constraints i want to worry about on my
system like if i'm working in the
uh language planes then i pretty much
want this to be like seven or eight bits
per character
i don't want to pay a penalty to encode
a lot of characters that are not going
to show up in my data stream a lot
but i might want this to extend so then
i have variable length encoding like
utf-8 or i could go utf-16
which is kind of common in the java
world so you'll see this a lot
and then i could say well i could just
make it big enough to cover every
character which means that
pretty much everyone is wasting 24 bits
unless you're
you know in the ancient sumerian
so is glyph is glyph kind of like a
proper term there or i mean in
linguistics we would talk about
like the kanji that you that you wrote
to be like a
a logogram and so photographs yes
yeah say it's the same term it's
interchangeable but um
is that just okay
i think i'm following you sorry i had to
so this encoding that you're talking
about is for
to basically represent all of the
um systems of of human
communication like all the different
symbols and all of that this is kind of
the set of all
characters um and then we can talk about
the set of all
encodings of those characters and it's a
little bit more complicated than what
last miles is talking about but
we can i i can tell you a lot about
internationalization later so we'll
we'll get to this topic when we're
sort of ready for it but anyway the
moral of the story is that this
didn't really um work for our basic
character definition anymore so
we wanted to move out of this world of
these sort of like non-specific types
and types that would change
depending on what platform you were on
or which compiler or which standard
and that's actually the creation of
what we've been what our second topic is
of today which is our fixed size types
and these are related to these you know
they were designed to be kind of like
quick to pick up if you were used to
like the old style types
but and see you later tyler thanks for
dropping by
um but they're actually incredibly
specific and they spell out
exactly how big they are no matter what
so this
improved portability massively and they
punted on care by the way so they
basically said look if you want to get
the world of all of this stuff it's not
going to fit into a type because it
really depends on
how you want to encode it and you know
how you want to do your data processing
that basically the standards body said
we're just not going to take a stance on
that we're going to leave character as
pretty much
eight so then you know that's actually
what i'm going to show you over here
which so these things have things which
very quickly whether they're signed or
unsigned which is typically denoted as
a u and then there's a basic type so
this is
you know this is our sign or unsign
specifier then there's our basic type
and this is something that looks like
what you've seen
in the past so that would be like for
example yeah
and and then there's a
bit size just to make sure that this is
totally a hundred percent
clear what this means so this is
the bit size is like 32 bits and that
32 bits and i don't care how you
interpret the integer it's always
32 bits so and
the specifier that we're using the
standard convention the underscore
type so um this style
what's the underscore t thing it's
basically just i'm typing
just convention type basically like this
is to say that
we're using the new style types because
you know some people were already
starting to use
like things like their own uints you
know in their own uint
32 and you know whatever so
um this this just to make sure we didn't
over that we added an underscore t to
the standard to say like okay this is
new stuff
um gotcha okay so character
in this world because like i just told
you doesn't really make any sense
because it depends on how you want to do
encoding and it depends if you want to
you know unicode 8 unit code 32 or if
you want to use something like shift
gis or whatever um there was a whole
world of sort of encoding stuff they
didn't want to get into so they just
this is now uint 8.
so it's no longer it
really we want to treat this as 8 bits
and that's it so this is an 8 bit number
so as we saw earlier when we were sort
of warming up like
we can treat characters as numbers and
this really just kind of formalized that
they said
if you want to add the semantics of a
character on it it doesn't really belong
in the language standard anyway
unless you're doing ascii which i think
pretty much in there okay so and then
you know if we drop this u then that
implies that it's signed
so you know we can say like int 32
we can do this on a lot of platforms too
and actually spell out the s so
that's that's kind of implementation
stuff we're going to get to in a minute
so all right high level does that make
sense i think so
apparently i think so okay um
and nathaniel don't don't show her the
dark magic yet
boy okay um so i'm gonna clear your
program here
and we're going to bring this back
to our learning interface okay
so all of these types are specified
they're specified in a few different
places but the way that i'm going to
show you is we're going to use the
numeric types which is standard int
so this is very portable it's available
just about everywhere
once you include that you can now start
using these new types
so before when you were doing something
like an in
for a counter you know and you really
meant you know
something like this which really sort of
implied that you were
probably going to use it unsigned anyway
we could actually be explicit about that
now and we could do something like this
and you'll notice it changed color as
soon as i dropped that t in there
yep so um
and this is going to invoke the new
and if we want to look at the size of
these things i'm going to
lose the glove for the moment because i
think we're good on whiteboard stuff
then this is going to be
so i didn't show you this specifier but
basically we did
d uh for sort of decimal yep
l implies that it's long so it basically
just usually means double
the size of whatever the type is okay
so it turns out that they actually added
a new type which is this
what and this is basically
i don't i'll get to that in a minute
actually but that's getting a little bit
into standard
stuff but um if i
if i take this thing and i run my sizeof
i can add a cast here and basically just
say like okay show me the size of
actually i won't do the cast i'll do
that show me the size of i
okay so what are we gonna see
um so the deep is the default
well i i don't know what the default is
first we have no idea
because it depends on what platform i
could tell you that it's going to end up
being the same as this other type but
um it is that was kind of the old world
of sort of less
standard types and that depends on which
standard you're using
so now we're going to use these new new
style types
and it's four now it's four octets
so bytes 32 in the modern sense which is
okay so that's our 32 bits now
um so i told you before a care
character turns into a uint eight
so there's your single byte type
yep okay and um
you know there's all the different
variations of this i'm actually gonna
you know you have to take too many notes
because i
brought up the wikipedia page for you
yay which has both the basic types
and the new um
the new types so this this kind of like
you know
if you get into this this other stuff um
yeah that that
when you start getting into like 128-bit
computing they realize like this is just
craziness so
like like how do you define a long long
long long
i mean it's is that using the 32-bit
long is that you know so
anyway um this this is something that we
can use in
new code to specify types that we want
some precision on size so
we're still being a little bit old
school because we're using the standard
convention and actually this should have
these i don't know where that went to um
but uh we can actually move to the other
yes strophium is right standard long
time ago in a galaxy far far
so these are like you can think of these
as the portable new types and
that's if you're writing new c code you
probably want to be there
as opposed to using the old style types
i i
i'll use whatever i mean you're kind of
making a judgment call on like where
your program's going to live and one of
those funny things about
programs is that there's no more
permanent program
than a temporary one
no more permanent solution than a
temporary solution
so uh be careful but
um so if we want to do our basic like
loop counters and stuff like that we can
this is basically our care you know if
we're thinking about it and now we don't
have to worry about
signed anymore versus unsigned we could
be clear or we can just drop
it um and i think this one is
yeah this is going to be fine and i
think this is no longer
i think this was rejected yeah okay good
and you get your error messages and your
output which is perfect
um okay so um this would be
the direct equivalent of your character
type so
let's um let's just bump this back up to
our normal sort of int except we're
going to go with the unsigned version of
and now why don't you give me a loop
counter using that j
so let's do a um a simple uh
print the first five numbers again
but using i mean it's going to be no
different right well except for the type
but you already wrote that well yes i'll
fix that for you no no no no
no problem solved
um oh i think there's an underscore t
here okay
all right there we go yeah
let's make that zero okay and then
yeah it'll change color when you get it
that's helpful um okay so please start
um that's not a brace
and what did you want it to print uh
let's let's start with our hello world
which is our first five characters
of the alphabet hey
okay we want to be fancy see people so
we can put the
type specifier right in the yes i just
remembered that
like strophium says we gotta write it as
hard as possible to read now this is
actually good for scope reasons we
talked about before
oopsies what oh maybe i need to like
yeah okay there we go i'm gonna
clear your output so we can see its
all right what are we forgetting between
these lines
um which lines i mean in the output
yeah the the new line but how would i
put it with put care i don't think we
ever did that
it's actually just a character so it
worked we didn't actually do it with
putcare but it works the same as
with printf
yeah but in printf we have like we we
the string quotations so we can have
more than one characters here we already
have no we need to know
yeah that's what i thought okay because
you can't you can only have one yes
that makes sense
yeah it's just a normal character okay
there you go
okay so new types we know why they're
beautiful because they
tell us exactly how big they are no
no portability issues with sizes and
whatever and this is this is kind of the
future so
i'll um i'll just drop you the
link to this on the wikipedia so that
you can go look at
all of its wonderful gory history
but all right so how do you feel about
that topic
i feel good i feel good i mean i think
it's it's i mean practice like anything
else right i mean
yeah yeah and i think but all of the
types like the fix types that we covered
today gonna take me a bit of
i don't know practice before i kind of
intuitively want to write out this long
type instead of just saying int so yeah
i think that'll just take practice i'm
not really gonna ding either way in
like your first taste to see course but
i it's this is definitely like if you're
as you're doing more c like you're
definitely going to want to be using the
portable types because
reasons um i think later on i'm saving
this for you we're going to go into the
lib png
code which is written in c for decoding
png files like you know png images
and you can see some of the battle scars
of the history
of oh boy of all this stuff okay so um
good well that means we can get into
topics right