#BB12

  Переглядів 5,219

Ralph S Bacon

Ralph S Bacon

4 місяці тому

It's true! At the beginner to moderate hobbyist coder, pointers are just trouble 😮
► PCBWay $5 for 10 pieces www.pcbway.com
00:00 Welcome Back
00:01 Intro and quick C++ vs C discussion
04:43 Why the need for references or pointers?
10:08 References walkthrough
16:50 Pointers walkthrough
31:03 Conclusion
GitHub entry for this video: github.com/RalphBacon/BB12-Po...
which contains the example files used in the demo.
So you asked "What about pointers, Ralph?". And I kept telling you, "Not needed". I was finally brow-beaten, er, sorry, "persuaded" to show you the difference between C++ user-friendly References and C-style, hard-to-decipher (and use) Pointers.
It is, of course, good to know about pointers, as other people's code might be full of them. Especially libraries, ported from the C language. But it doesn't mean you should be tempted to use them when we have References available.
Unless you know differently? Your views in the comments, please!
► List of all my videos
(Special thanks to Michael Kurt Vogel for compiling this)
bit.ly/UKpostsVideoList-RalphB...
► If you like this video please give it a thumbs up, share it and if you're not already subscribed please consider doing so and joining me on my Arduinite (and other μControllers) journey
My channel, GitHub and other stuff are here:
------------------------------------------------------------------
• / ralphbacon
• github.com/RalphBacon
• buymeacoffee.com/ralphbacon
------------------------------------------------------------------
My ABOUT page with email address: / ralphbacon

КОМЕНТАРІ: 145
@medrolet
@medrolet 4 місяці тому
Welcome back, Ralph. You've been missed.👍
@RalphBacon
@RalphBacon 4 місяці тому
Thank you! And a Merry Xmas to you too! 🎄🎅
@SpinStar1956
@SpinStar1956 4 місяці тому
Bacon is always missed when not around!!! 🤣😂🤣
@hansdegroot652
@hansdegroot652 26 днів тому
Yes but he is missing again for quite some time now
@philipreed2758
@philipreed2758 24 дні тому
@@hansdegroot652 i was just thinking the same as you today. i hope all is well. x
@rpr42
@rpr42 3 дні тому
Miss him as well. Hope he's doing well.
@hariseldon2577
@hariseldon2577 4 місяці тому
Was wondering where you where. Nice to have you back again.
@RalphBacon
@RalphBacon 4 місяці тому
Hey, thanks! And a Merry Xmas to you too! 🎄🎅
@ElieWar
@ElieWar 4 місяці тому
Good to see you back
@RalphBacon
@RalphBacon 4 місяці тому
Merry Xmas, Happy Holidays! 🎄❄️☃️
@SpinStar1956
@SpinStar1956 4 місяці тому
Pointers and References are always a tough subject to explain, and so dependent on using precise language to accurately describe. I think you did a great job of both describing and demonstrating the subject. I have for years used "int &x" but can see that "int& x" is actually much more accurate. And the double use-meaning of * is indeed confusing. Thanks and hope 2024 is a good one for all! 73...
@RalphBacon
@RalphBacon 4 місяці тому
Glad it was helpful! Ironically, since that video I've had to use pointers because the power that be at Espressif decided their interface to tasks was going to be a pointer. So it's always good to be aware of (as well as beware of) pointers!
@martin87865
@martin87865 4 місяці тому
Hi Ralph, so glad to see you back. I have really missed you, I have learnt so much from your tutorials over the years. please keep it going.
@RalphBacon
@RalphBacon 4 місяці тому
Noted!
@borayurt66
@borayurt66 4 місяці тому
Good to see you again Ralph, it has been some time.
@RalphBacon
@RalphBacon 4 місяці тому
It has been a while! Merry Xmas, Happy Holidays! 🎄❄️☃️
@tonybell1597
@tonybell1597 4 місяці тому
A Christmas Ralph vid… Thankyou.. Have a very Happy Christmas
@RalphBacon
@RalphBacon 4 місяці тому
Nice to see you here again! Merry Xmas, Happy Holidays! 🎄❄️☃️
@gregwmanning
@gregwmanning 4 місяці тому
Merry Christmas Ralph
@RalphBacon
@RalphBacon 4 місяці тому
Merry Xmas, Happy Holidays! 🎄❄️☃️
@user-xl6qu2jg4h
@user-xl6qu2jg4h 4 місяці тому
Good to see you again Ralph
@RalphBacon
@RalphBacon 4 місяці тому
Merry Xmas, Happy Holidays! 🎄❄️☃️
@willofirony
@willofirony 4 місяці тому
Welcome back and Merry Christmas
@RalphBacon
@RalphBacon 4 місяці тому
Merry Xmas, Happy Holidays! 🎄❄️☃️
@fredflintstone1
@fredflintstone1 4 місяці тому
Ralph! Glad to see you are well, and I wish you and your family Merry Christmas and a happy New year, and I hope to see more videos from you in the new year 🙂
@RalphBacon
@RalphBacon 4 місяці тому
I hope so too! And a Merry Xmas to you too! 🎄🎅
@OsoPolarClone
@OsoPolarClone 4 місяці тому
What an early Christmas Present! Glad to see you back.
@RalphBacon
@RalphBacon 4 місяці тому
And a Merry Xmas to you too! 🎄🎅
@basiljackson3829
@basiljackson3829 4 місяці тому
Excellent video. Very useful. The only advantage to pointers is that the caller KNOWS that the function COULD change the value. That prevents a debugging nightmare when the function changes the value of a parameter and the calling routing still relies on the ORIGINAL value.
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 4 місяці тому
This could be a big problem! but then I'm old and stuck in my ways. Still not a problem if you know what it will do due to being well documented code. Still find for embedded work C works just fine for me. Just had to laugh as i saw "A reference allows you to manipulate an object using a pointer, but without the pointer syntax of referencing and dereferencing" so it's just a pointer with an overcoat on to hide it's internals.🙂
@RalphBacon
@RalphBacon 4 місяці тому
@TheEmbeddedHobbyist Yes, like most syntactic sugar, references are (behind the scenes) pointers but with a friendly face. Then again, all variables are really pointers (if you really want to stretch the analogy). And it cleans up after itself, unlike pointers.
@RalphBacon
@RalphBacon 4 місяці тому
@basicjackson3829 Agreed, in principal; but any function that changes the incoming parameters without good reason is a bad function. It should make a copy of the underlying values and change those, for internal use.
@andreweastland9634
@andreweastland9634 4 місяці тому
Now I no longer know if a function is going to change my variables. With pointers it is pretty obvious when a function has access to my data. It is not complicated to use pointers. It is only made complicated by people explaining it who don't really understand pointers. What's difficult about address of (&) and contents of (*) operators? That's all it boils down to. Merry Christmas and thanks for another great video.
@RalphBacon
@RalphBacon 4 місяці тому
Well, the fact that you don't think it difficult to understand pointers means you're one of the viewers at whom this video was not aimed! Once you "get it" even the rather tortuous code I wrote the other day is clear: applianceType thisApplianceType = *(applianceType *)parameters; becomes clear. Why such nonsense? Because on an ESP32 Espressif decided that the parameter to a task was a (void) pointer. Crazy. And that's because all Espressif coders write in C not C++ (pretty much).
@JCWren
@JCWren 4 місяці тому
I was fixing to post the same thing. I don't want functions autonomously changing variables, I want to pass a pointer so I explicitly know that I'm passing a variable that's going to be altered. I've been writing code for over 40 years and used or experimented with as many languages, and next to COBOL and Python, C++ is one of the worst. Oh, it has some nice features, but the main problem is the way people unknowingly (or deliberately) obfuscate code or make it insanely difficult to debug because of multiple inheritances and such. Also putting code in header files -- That's a crime against nature in my book. My preferred language of choice is C, followed by Forth and assembly (for just about any processor). BTW, Ralph, you're missing the on your print() in line 16 :)
@danielcastillo357
@danielcastillo357 Місяць тому
Ralph I hope is well in England. Looking forward to your next program/video.
@RalphBacon
@RalphBacon Місяць тому
All is well. Thanks for your concern. 👍 Actually, all is well with ME, but England is currently going to the dogs with high interest rates, junior doctors on strike, train drivers ditto, food price inflation out of control and two of our lovely Royal Family now with the big C diagnoses. Can it get any worse? (Rhetorical, of course it can, but let's hope it doesn't). I blame Covid-19 and Brexit - they have decimated a once proud and prosperous country. 😢
@chriskeeble
@chriskeeble Місяць тому
@@RalphBacon Good to see you're still around - have really enjoyed finding your videos recently as I started out on my own Arduino adventure. Have just been sim racing this evening with a bespoke sim racing button box, using an Arduino Leonardo, a good deal of which I learnt about through your videos. As for Brexit - have a look at Ireland and Scotland just this week - we are better off out of the corrupt EU. And as for COVID - our politicians (along with many others around the world) lied, lied and lied again - all while they lined their own pockets and those of their mates. And as for the Royal Family.... sadly there isn't an honest one among them.
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 4 місяці тому
Welcome back Ralph been awhile since the last old grey cell workout.
@RalphBacon
@RalphBacon 4 місяці тому
I'm not sure whether the workout was for me or you, but I hope it clarifies things for Arduites, generally!
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 4 місяці тому
@@RalphBaconI used to liked doing software / firmware V&V at a medical start-up, checking the code to the standards was always a good grey cell work out. Nowadays getting a nudge to go and look something up gives them a little tweak. 🙂
@_AmHam_
@_AmHam_ 4 місяці тому
Hi Ralph ! You are missed ! Hope everything is well on your side. Merry Christmas and happy new year 🎉
@RalphBacon
@RalphBacon 4 місяці тому
Happy new year! Everything fine here, just too much "other work", but I may still be able to make the occasional video.
@stevex3976
@stevex3976 4 місяці тому
Merry Christmas a very Happy New Year! Glad you are back.
@RalphBacon
@RalphBacon 4 місяці тому
Same to you! 🎄🎅
@computergururick
@computergururick 21 день тому
Great explanation of pointers.
@RalphBacon
@RalphBacon 21 день тому
Glad you think so!
@Friendroid
@Friendroid 4 місяці тому
merry xmas, ralph, for you and your family! thank you for all your teachings :)
@RalphBacon
@RalphBacon 4 місяці тому
My pleasure! And a Merry Xmas to you too! 🎄🎅
@daveharris3384
@daveharris3384 4 місяці тому
Welcome back.
@RalphBacon
@RalphBacon 4 місяці тому
And a Merry Xmas to you too! 🎄🎅
@MikesAllotment
@MikesAllotment 4 місяці тому
Great to see you back Ralph - we've missed you. Another excellent video - very clearly explained, and I have to admit to being one of those old C programmers who used pointers many years ago long before C++ even existed. Bought back a lot of fond memories. Merry Xmas !
@RalphBacon
@RalphBacon 4 місяці тому
Glad you enjoyed it, although as a seasoned C programmer you have my full permission (like you need it!) to continue using pointers! 😆
@markgreco1962
@markgreco1962 4 місяці тому
Happy holidays Ralph
@RalphBacon
@RalphBacon 4 місяці тому
And Happy Holidays to you too! 🎄🎅
@DavidUnderhill
@DavidUnderhill 4 місяці тому
Thank you for the infomative video. My old programming lecturer at university spent over 3 hrs explaining pointers usage in C++. At the end of the 2 part tutorial he said any programming assignment submitted that used pointers where referencing could be used instead would lose points. This was 30 years ago, paid off bigtime as most programs where (and still are) easier to debug.
@RalphBacon
@RalphBacon 4 місяці тому
Great to hear! I like that lecturer already.
@douglasosborn3378
@douglasosborn3378 3 місяці тому
Great episode! It took me back to my early programming days. I wasn’t, and still am not as clever as you true professional programmers. I never will be, sadly.
@RalphBacon
@RalphBacon 3 місяці тому
Glad you enjoyed it! But don't underestimate your skills, Doug.
@douglasosborn3378
@douglasosborn3378 8 днів тому
I’m sat here watching you videos on state machines and it hit me, I never thanked you for your kind supportive response to my comment. Thank you
@colepdx187
@colepdx187 4 місяці тому
Ralph! Good to see you, sir.
@RalphBacon
@RalphBacon 4 місяці тому
You too!
@gpTeacher
@gpTeacher 4 місяці тому
Very informative Ralph. Thank you! I was worried! I was ready to send out ASAR to look for you! (Arduino Search and Rescue!). Happy holidays to you and your family 🙂
@RalphBacon
@RalphBacon 4 місяці тому
Thanks Gord, but no AS&R required, I was just held captive in my workshop by "other work"! Merry Xmas and a Happy New Year to you too!
@ianneill9188
@ianneill9188 4 місяці тому
Thanks Ralph, just what I needed. An earlier video of yours introduced me to references and this one tied up a few loose ends and answered some questions I had!
@RalphBacon
@RalphBacon 4 місяці тому
Glad it helped!
@danman32
@danman32 4 місяці тому
Thanks Ralph, this clears up a lot. Will take some time to sink in. It is valuable to me as I have been working on an ambitious project that involves porting over Arduino IDE based code and libraries to Pico SDK code using cmake in VSC. Yes, I know, the SDK/cmake platform is designed for C but it supports CPP just fine. A few of the hiccups I've encountered is converting progmem references which uses pointers (or maybe it has been reference?), the other is passing arrays. Perhaps beyond the scope of this topic, but I had found arrays, or rather large memory locations being passed the start of the memory location, and a variable in the function indexing from the start of the memory location by adding to the pointer value. That "mistake" of printing the value of the pointer rather than the value of what the pointer points to could be a good trick for debugging, or at least exploring.
@RalphBacon
@RalphBacon 4 місяці тому
Arrays are always passed by reference (never by value) because all you get is the address of the first element of the array. You don't even get the size of the array.😲 Hence the better use of vectors in C++, at least. Good luck with your porting project.
@danman32
@danman32 4 місяці тому
@@RalphBacon I'm aware that arrays are always passed by reference. But I wanted the function to use the memory area pointed to as it sees fit, but compiler wants to keep the dimensions and data type consistent from original I figured workarounds
@digihz_data
@digihz_data 4 місяці тому
Happy Christmas Ralph.
@RalphBacon
@RalphBacon 4 місяці тому
Thank you, to you too! 🎄🎅
@williammcdonald9086
@williammcdonald9086 4 місяці тому
Thanks Ralph. I was playing with pointers a while back where my function was simply adding 1 to the passed parameter. Today, thanks to you, I discovered that *x += 1; (works) is not the same as *x++: (does not work). That one kicked my butt for quite a while since x++; and x += 1; normally functions the same.
@RalphBacon
@RalphBacon 4 місяці тому
Ah yes, the shorthand methods are tricky to use with pointers. But good job in figuring it out. 👍
@henrybecker2842
@henrybecker2842 4 місяці тому
That was very very helpful. When I programmed using 360 assembly and PL/S pointers were always used. I never understood why they are used in modern languages, except as you mentioned yo minimize the overhead of moving large quantities of characters or numbers. Thank you very much
@RalphBacon
@RalphBacon 4 місяці тому
Glad you found it useful!
@sveinarsandvin6418
@sveinarsandvin6418 4 місяці тому
Friendly explenation. Very good.
@RalphBacon
@RalphBacon 4 місяці тому
Many thanks!
@rinokentie8653
@rinokentie8653 4 місяці тому
Very useful, thanks!
@RalphBacon
@RalphBacon 4 місяці тому
Glad you liked it. And a Merry Xmas to you too! 🎄🎅
@grahamwise5719
@grahamwise5719 4 місяці тому
Good video, pointers are useful when sending bytes over a radio link, and say you have floats to send byte by byte and reassemble at the receiver, but don't make mistakes. take care Graham
@RalphBacon
@RalphBacon 4 місяці тому
Well, maybe, Graham but I don't use radio links like that. I just send out packets of data (perhaps using ESP-NOW) and let the device figure out how to do it! Still gets there! Thanks for your Best Wishes and the same to you 🎄
@MrJozza65
@MrJozza65 4 місяці тому
Completely with you on this Ralph; pointers have their uses, but there's so much possibility of inadvertently creating bugs that I have avoided them for years. By reference and by value should be enough for pretty much all tasks, unless you are hitting the hardware and need every clock tick available, but in that case you would probably be programming a PIC in assembler and not an Arduino in C++ 🙂
@RalphBacon
@RalphBacon 4 місяці тому
Agreed. C++ gives us References for a reason: to avoid the "challenges" of using Pointers! We could write a bit of assembler for Arduinos too, but does anyone do that except for some real edge cases?
@CXensation
@CXensation 4 місяці тому
Nice to see you back Ralph. Interesting topic - as always. Have to admit I watched it over again before I finally got it
@RalphBacon
@RalphBacon 4 місяці тому
Good stuff! Yes, it may well take a few watches to get it to click.
@andymouse
@andymouse 4 місяці тому
Howdy Ralph !
@RalphBacon
@RalphBacon 4 місяці тому
Dare I say "squeak"? Nice to see you here again!
@andymouse
@andymouse 4 місяці тому
Squeak !!@@RalphBacon
@keldsor
@keldsor 4 місяці тому
Oh, hi - welcome back ... where have you been for so long ? Can you recommend a project for a HOME BURGLER ALARM with PIRs, maybe cameras, HORNs/Sirenes for making noise with wireless ON/OFF arming ! Maybe even by use of internet/Android phone. I have some wired 12V PIRs /HORNs/Sirenes from an older project already placed 😉
@RalphBacon
@RalphBacon 4 місяці тому
Rather than following someone else's project why not start your own. You have already excluded microcontrollers without Wi-Fi because you want and Internet/Phone interface. The ESP32 is the device of choice right now (if you are not using a Raspberry Pi) with decent processing power, Wi-Fi and lots of memory, especially if you get the 8Mb or even 16Mb versions. You could create something in about 10 minutes as a proof of concept and work up from there. Alternatively look at ESPHome (esphome.io/index.html ) which probably has a project you want just waiting for you!
@keldsor
@keldsor 4 місяці тому
@@RalphBacon THX - I'll look into your proposals and the links 🙂
@jadus2198
@jadus2198 3 місяці тому
Pointers can be useful if you are using for example an array of structs, but if you are using an array of structs and you need indexing or something like that, then you will probably know how to use it anyway's. I do a lot of programming in structured text, which is derived from C and CPP. I like the use of pointers in structured text a little more. If you declare a pointer for an integer, it is declared as ^INT (you see it is pointing to something). In the code, if you want the value of the pointer, the syntax is ^value, if you want the pointer address it is #value. If you think about it, # is the house and ^ is what is living under the roof. In C I always have to look it up to know if I have to use & or * although the syntax is the same, only different symbols. (matter of using it more often, I know).
@RalphBacon
@RalphBacon 3 місяці тому
In short, pointers can be a minefield. Like a box of matches in the hands of a child. Ready to burn you (or the house down) if used incorrectly. There are doubtless scenarios where pointers would be useful but by the time you need that extra functionality I would think the expertise would be there too. I use pointers now and again - but try very hard to stick to C++ coding and not drop down to C constructs.
@--JYM-Rescuing-SS-Minnow
@--JYM-Rescuing-SS-Minnow 4 місяці тому
hi Ralph...love U'r stuff.. so U'll REF an INT 2 make the VAR.....end.....An integer is a whole number that can be positive, negative, or zero....... In C language, a variable is the name of a memory location that is used for storing data...A variable is a characteristic that can be measured and that can assume different values.👀 U could have a sensor feeding int, then var would find a value. is there a print yet..& it proves that U'r stack will feed in the direction U want it to go...good luck O'l boy!!🌞🌻
@RalphBacon
@RalphBacon 4 місяці тому
Well, I'm sure that was crystal clear when you wrote your comment but I'm having a minor issue sorting the wheat from the chaff. But I'll accept your word on what you reckon is the best way to go! Merry Xmas, Happy Holidays! 🎄❄️☃️
@steverileyretired
@steverileyretired 4 місяці тому
Very Interesting
@RalphBacon
@RalphBacon 4 місяці тому
Glad you think so! And a Merry Xmas to you too! 🎄🎅
@lilbuzz999
@lilbuzz999 4 місяці тому
Welcome back Ralph! Thanks for another great video. Happy Holidays (politically correct U.S. way of saying Merry Christmas) to you and yours.
@RalphBacon
@RalphBacon 4 місяці тому
Merry Christmas and A Happy New Year, in a totally non-PC UK way of wishing your the absolute best! 🎅🎄😁
@Tony770jr
@Tony770jr 4 місяці тому
Good point, no pun intended!
@RalphBacon
@RalphBacon 4 місяці тому
I won't reference your reply then 😲 in writing this response.
@Ed19601
@Ed19601 4 місяці тому
Merry christmas
@RalphBacon
@RalphBacon 4 місяці тому
Thank you, to you too! 🎄🎅
@TradieTrev
@TradieTrev 4 місяці тому
It was brought to my attention from a person I really respect to follow the Barr Groups methods for C, how does their implementation convert to C++ from a newbie prospective?
@RalphBacon
@RalphBacon 4 місяці тому
As many will tell you, C++ is not C. Neither is it just "C with classes". Bjarne Stroustrup found C unnecessarily primitive and prone to error. He wanted a static type safe language along with abstraction (OOP). The rest, as they say, is history. Of course, every C++ compiler will also compile C without issue. In fact, some C functions are now part of the C++ language too so the lines can become blurred and confusing. So many supposed C++ developers still use C-style arrays when they should be using vectors; probably because they have a C background - and it works! I can only assume that there are resources out there showing the true C++ path, or what NOT to do in C++ that you do in C. Using pointers willy-nilly, for example, when references were the C++ replacement. The "best" C++ developers are those who learned C++ without learning C. The "worst" are those that know C well, and then "convert", as you put it, to C++ in a haphazard manner. Buy Bjarne's "C++ Programming Language", 3rd edition (or later if there is one). It's not what I call an easy read, but it is the definitive C++ language reference. But others may serve your purpose better by presenting the material in an easier-to-read manner (including a better font! Doh!) with, dare I say it, simpler, Real Life examples!
@stuartajc8141
@stuartajc8141 4 місяці тому
At 25:15 you show the value of the pointers as big hex numbers. But in Arduino pointers are two bytes, so how come the pointer values are so huge? Is it because its running on your 64 bit PC? Welcome back, by the way, and looking forward to more videos in the New Year
@RalphBacon
@RalphBacon 4 місяці тому
Yes, spot on! Because I was running this on a 64-bit PC, the pointers (an integer) were 8-bytes long (64-bits divided by 8-bit bytes = 8 bytes). On a 32-bit (eg ESP32 or older Windows PC) machine each pointer/integer is 4 bytes long, and on the humble 8-bit Arduino they use 2-bytes, 16-bit integers, the compiler being optimised for this - the C language requires all integers to be (at least) 16 bits unless you use a definition such as int8_t which "forces" the compiler to use a single byte.
@stuartajc8141
@stuartajc8141 4 місяці тому
@@RalphBacon Thanks. Supplementary question: everywhere it says Arduino pointers are 2 bytes/16 bits, which can address 64K assuming unsigned int. But some devices have much more memory than that, such as the RPi Pico, so when I compile the sketch for it I see: Sketch uses 377156 bytes (18%) of program storage space. Maximum is 2093056 bytes. Do pointer sizes change with the device you define in the IDE?
@qcnck2776
@qcnck2776 4 місяці тому
@@stuartajc8141 Pointers are very specific to the device, and since they point to a memory address, their size is going to depend on the number of bytes used to fully address the memory space. A good way to know for sure is to use sizeof(ptr) Best not to assume😀
@stuartajc8141
@stuartajc8141 4 місяці тому
Thanks@@qcnck2776 it's something I never thought about until Ralph said they were always 16 bits, which is what the Arduino docs say. But I guess they are referring to the original MCUs with 64KB memory. Now that the Arduino IDE can compile for loads of boards with much more memory they should update the docs.
@RalphBacon
@RalphBacon 4 місяці тому
What @qcnck2776 says is spot on. The pointer must be able to contain the memory address of the last possible byte of memory. I think Intel 80286 (24-bit) got this wrong and they had to "page" memory (max 16MB) for it all to work with virtual memory (up to 1GB). But in some ways the size of the pointer is irrelevant; what are you doing that you need to know the size of a pointer, rather than "just using it"?
@jasonlee3247
@jasonlee3247 4 місяці тому
Back in the old days, Macintosh programming used handles which I believe were pointers to a pointer. Lots of double * in those days 😂
@RalphBacon
@RalphBacon 4 місяці тому
Hmm. Pointers to pointers still exist but, as you might imagine, I decided not to even mention them! 😆
@EmbeddedEnigma
@EmbeddedEnigma 4 місяці тому
pointers are very usefull when interfacing with memory interfaces and stuff like that ;) nothing will replace pointers anytime soon in embedded .
@RalphBacon
@RalphBacon 4 місяці тому
There are always exceptions to the rule and this is doubtless one of them!
@KaiseruSoze
@KaiseruSoze 4 місяці тому
I have had to use pointers when parsing a response from an http get. And when processing a packet from a TCP/IP response. A pain in the butt. Especially when dealing with big endians. I could have created a struct for each case, but I couldn't anticipate each case, so pointers.
@RalphBacon
@RalphBacon 4 місяці тому
Sometimes you have to grasp the nettle and do what must be done 😟
@SprocketN
@SprocketN 4 місяці тому
I’ve done similar things but, like this: int a = 5; int b = 10; a , b = swap(a , b); int swap(a , b) { int temp = a; a = b; b = temp; return a, b; }
@K5HJ
@K5HJ 4 місяці тому
This won't work in C. You can only return a single value.
@SprocketN
@SprocketN 4 місяці тому
@@K5HJ Oops! I write programs in Python and several other languages (for fun). I often get mixed up with what each language can do. Thanks for correcting my mistake.
@RalphBacon
@RalphBacon 4 місяці тому
Yes, I read this last night and saw that it would never work, but by this morning @K5HJ has already written a response explaining all.
@lindsaymcphee2885
@lindsaymcphee2885 4 місяці тому
As a predominantly VB6 programmer coming to c/c++/Arduino/esp32 pass byVal and pass byRef is familiar territory. The majority of texts and videos about pointers are far to verbose and over complicated, because they never show you the pass byRef syntax which would as you rightly say be enough for most people learning the language. I am now wondering whether Java and JavaScript have similar syntax.
@RalphBacon
@RalphBacon 4 місяці тому
Java is always Pass by Value. JavaScript too. Unless you are passing an object in which case it becomes a Pass by Reference, if you change the (underlying) members of that object. I believe there are some anomalies in both languages but I steer clear of those.
@kentswanson2807
@kentswanson2807 4 місяці тому
If you are sorting a bunch of data,, not a 1000 bytes, but even 5 or 10, but you have 50 of them. Wouldn't it be more economical to sort the pointers? Vs moving all those bytes around?
@RalphBacon
@RalphBacon 4 місяці тому
That depends on what the data is, Kent. A pointer is a two byte integer. If the data is bigger then, yes, it would be better to do so. But sorting character data is unusual; you would normally sort the index (which would probably be a one or two byte array). Very much depends on the application and data!
@hansdegroot652
@hansdegroot652 26 днів тому
Ralph where are youuuuu?
@RalphBacon
@RalphBacon 18 днів тому
I'm here somewhere... not sure where, right now. 🤷
@lilbuzz999
@lilbuzz999 Місяць тому
Ralph, is everything alright? Haven't heard anything from you in three months time.
@RalphBacon
@RalphBacon Місяць тому
Yes, indeed, thanks for asking. Taking a bit of a break from the YT treadmill although I have been extremely busy and productive in the last few months. I might even make a video or two about what I've been building!
@lilbuzz999
@lilbuzz999 Місяць тому
@@RalphBacon, can't wait!
@zyghom
@zyghom 27 днів тому
where is Mr. Ralph???
@RalphBacon
@RalphBacon 27 днів тому
Taking a break from UKposts whilst I do LOTS of "other work". There simply isn't enough time in a day to do both right now.
@fredflintstone1
@fredflintstone1 4 місяці тому
I can't see the point of this🙂
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 4 місяці тому
that's because you look more like a greyhound than a pointer. 🙂
@RalphBacon
@RalphBacon 4 місяці тому
It's the way you tell 'em, Barney!
@fredflintstone1
@fredflintstone1 4 місяці тому
@@RalphBacon I do my best to bring Xmas cheer🙂
@nexuzinnovation-com
@nexuzinnovation-com 2 місяці тому
Happy New Year Ralph, this year I only has time to back to hardware, hopefully things get smooth. Cheers.
@RalphBacon
@RalphBacon 2 місяці тому
Same to you! Busy, busy!
#BB9 Organising your code🧹for easier debugging and maintenance✅
18:45
#BB10 Namespaces & Macros for Arduino (and other) microcontrollers
19:06
Ralph S Bacon
Переглядів 13 тис.
Артем Пивоваров х Klavdia Petrivna - Барабан
03:16
Artem Pivovarov
Переглядів 8 млн
Эффект Карбонаро и пончики
01:01
История одного вокалиста
Переглядів 8 млн
are "smart pointers" actually smart?
9:44
Low Level Learning
Переглядів 67 тис.
#148 TCA9548A I2C MULTIPLEXER (& Voltage Shifter)
38:00
Ralph S Bacon
Переглядів 25 тис.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Переглядів 261 тис.
you will never ask about pointer arithmetic after watching this video
8:01
Low Level Learning
Переглядів 223 тис.
#BB5 Moving your Arduino to a multi-tasking State Machine - Easy Intro
24:10
Passing Pointers to Functions -- C++ Pointers Tutorial [7]
19:22
Professor Hank Stalica
Переглядів 1,4 тис.
#266 ESP32 Deep Sleep Project - Door Open/Closed Detection with ESP-NOW
25:18
you need to stop using print debugging (do THIS instead)
7:07
Low Level Learning
Переглядів 392 тис.
Лучший Смартфон До 149 Баксов!!!??? itel s24
20:25
РасПаковка ДваПаковка
Переглядів 54 тис.
M4 iPad Pro Impressions: Well This is Awkward
12:51
Marques Brownlee
Переглядів 5 млн
Fiber kablo
0:15
Elektrik-Elektronik
Переглядів 1,7 млн
How Neuralink Works 🧠
0:28
Zack D. Films
Переглядів 26 млн
APPLE УБИЛА ЕГО - iMac 27 5K
19:34
ЗЕ МАККЕРС
Переглядів 82 тис.
Рекламная уловка Apple 😏
0:59
Яблык
Переглядів 796 тис.