Notifications
Clear all

Help with c++ pointers

45 Posts
7 Users
5 Likes
2,304 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6893
 

@frogandtoad True, I just couldn't think of a better metaphor at the time.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

Posted by: @frogandtoad

@will

Posted by: @will

Posted by: @zander

@will Isn't the print result backwards? I would expect to see leftmost as 10001000 and rightmost as 10011001

Hey, I just made it work - I don't care what it does 🙂 

If the end result is incorrect, then other than compiling, you made nothing work 😉

Cheers

The OP asked why it wouldn't compile and I did fix that. Since the OP didn't state it's purpose it's not possible to say if the operation is right or wrong.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@frogandtoad

First of all thank you for your input.

First of all... you can't just shove 64 bits into 8 bits, without special casting techniques, but then again, why would you do such a thing?, I just can't understand why, other than to say the programmer is uneducated!

I don't see how I did that?

If you need and want to use 64 bits, then use 64 bits!

Which is why I defined message as 64 bits,

uint64_t message

The Arduino founders built these C++ functions for a reason... they know better than you!

That is good of them. Nothing like using things without knowing how they actually work. I wasn't actually using Arduino c++.  I am not sure what ide was being used to program the Pico I was using an online compiler.

It's so ironic that many people here actually advocate and push Python as being so much easier to learn... well guess what... C++ is JUST AS EASY, only if such people woke the hell up!

Python is a higher level language than c++. It doesn't really compare with c++ nor can it compete with c++ which is the king of languages when it comes to complete control.  What language you use depends on what you want to do with it.

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@frogandtoad

Such data structures (queue vs stack), have nothing to do with this at all... this is all about the true binary representation as far as I can tell?

@will

The OP asked why it wouldn't compile and I did fix that. Since the OP didn't state it's purpose it's not possible to say if the operation is right or wrong.

I did give the source of the original code and its use.
https://forum.dronebotworkshop.com/user-robot-projects/swarm-robotics/paged/4/#post-36043


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

Posted by: @robotbuilder

@will

The OP asked why it wouldn't compile and I did fix that. Since the OP didn't state it's purpose it's not possible to say if the operation is right or wrong.

I did give the source of the original code and its use.
https://forum.dronebotworkshop.com/user-robot-projects/swarm-robotics/paged/4/#post-36043

What does a thread on Swarm Robotics have to do with C++ pointers ?

In the original post which I answered there is no hint as to what the code is supposed to be doing and there is certainly no URL reference in there to the origin of the source.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@will 

What does a thread on Swarm Robotics have to do with C++ pointers ?

@thrandell
"One of the things I dig about C is the way you can use pointer variables to access data. The pointer variable in this code is used to access the contents of the message array one bit at a time."

In the original post which I answered there is no hint as to what the code is supposed to be doing and there is certainly no URL reference in there to the origin of the source.

At that point it wasn't relevant and your answer was fine there is no criticism here. I couldn't get the original to compile and now I have code that does compile. Thank you.

@frogandtoad also provided more ways of handling the problem with,
bitRead(number, bitPos)
but it wasn't in the original code nor would it be useful if for example I wanted to do the same in Assembler or some other language lacking such a function. Extracting bits isn't all that hard and why not know how the function works?

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Firstly, let me apologise... I went a little too hard on you!
Comments in-line:

Posted by: @robotbuilder

@frogandtoad

First of all thank you for your input.

First of all... you can't just shove 64 bits into 8 bits, without special casting techniques, but then again, why would you do such a thing?, I just can't understand why, other than to say the programmer is uneducated!

I don't see how I did that?

Again, I apologise... I was referring to the casting of 8 bytes to 64 bits, and also, I was referring to the original code, just to clear that up.

If you need and want to use 64 bits, then use 64 bits!

Which is why I defined message as 64 bits,

uint64_t message

I thought that was part of the original code?

The Arduino founders built these C++ functions for a reason... they know better than you!

That is good of them. Nothing like using things without knowing how they actually work. I wasn't actually using Arduino c++.  I am not sure what ide was being used to program the Pico I was using an online compiler.

Also, by you... I mean't we, us everyone!

It's so ironic that many people here actually advocate and push Python as being so much easier to learn... well guess what... C++ is JUST AS EASY, only if such people woke the hell up!

Python is a higher level language than c++. It doesn't really compare with c++ nor can it compete with c++ which is the king of languages when it comes to complete control.  What language you use depends on what you want to do with it.

I was just trying to point out that C++ can be just as easy as python, if people just embrace it's default ISO libraries, and this is a classic case where C++ is never embraced, making it look and seem harder to learn, hence my frustration.

My real message is (as always), don't learn C before C++, because these problems you have presented will always trip people up!

Cheers


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@frogandtoad 

 

I was just trying to point out that C++ can be just as easy as python, if people just embrace it's default ISO libraries, and this is a classic case where C++ is never embraced, making it look and seem harder to learn, hence my frustration.

You need to understand where some of us hobby level programmers are coming from. To promote a language you need to show how it can easily be used to allow them to quickly come up with a solution to their problem.

It is not learning the c++ language that is the problem.  It is the programming environment it uses that is the problem and it keeps getting harder for certain tasks. Really I tried many time to use graphics with c++ but just couldn't get it to work.  FreeBASIC worked first go simple and easy and compiled to super fast code. Processing is also easy to use with graphics.  Python does require installing libraries but that process is made easy unlike the convoluted and ultimate fail to do likewise with C++.

Also if you are trying to do a project where the example is in Python using libraries how do you translate that into a c++ program?

 

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Posted by: @robotbuilder

@frogandtoad 

I was just trying to point out that C++ can be just as easy as python, if people just embrace it's default ISO libraries, and this is a classic case where C++ is never embraced, making it look and seem harder to learn, hence my frustration.

You need to understand where some of us hobby level programmers are coming from.

I understand exactly where you're coming from, that's why I responded to your posts with examples.

To promote a language you need to show how it can easily be used to allow them to quickly come up with a solution to their problem.

To be frank, your comment is utterly misguided!

Firstly, I wasn't promoting a new language, I was promoting the proper intended use of ISO C++ (the language in which you asked for help with), which you don't seem to be able to grasp - I actually went out of my way to code, and show you how easy it can be used, and with different examples to demonstrate that fact!

It is not learning the c++ language that is the problem. 

Actually, it is, and as harsh as this may sound... you, like many others, have never really taken the time to actually learn it - that is the real problem I'm afraid.

It is the programming environment it uses that is the problem and it keeps getting harder for certain tasks.

The environment (your particular environment), is your responsibility to set up correctly, and... one time only! This goes for all languages/workflows... do you have a specific example where this is the fault of C++?

Really I tried many time to use graphics with c++ but just couldn't get it to work. 

I'm sure it's not that difficult if you really want it.
Did you seek any help?  What were the issues?

FreeBASIC worked first go simple and easy and compiled to super fast code. Processing is also easy to use with graphics. 

Indeed, they are great tools, specifically built for rapid development, but super fast... I'm not sure about that.  Please understand that C++ is a multi-paradigm language, offering a wide scale variety of power, hence the reason it doesn't play what you want straight out of the box.  BTW, C++ evolves and improves every three years, and if you haven't kept up with (the Jones's) it's new features since the "Turbo C++" days, then how on earth can you or anyone else make any judgement at all on how easy it is in comparison to any other language?

Python does require installing libraries but that process is made easy unlike the convoluted and ultimate fail to do likewise with C++.

Translation - You couldn't take the time to learn how to #include a <header>, and provide an environment variable path to your IDE of choice, for headers, libraries and DLL's!

Yep, that sums it up!

Also if you are trying to do a project where the example is in Python using libraries how do you translate that into a c++ program?

The same way you do, no matter what the languages are... by first understanding the languages of source and target you're working with, otherwise, you can use language translators to do the work for you, but even in that case, you still need to understand the languages you're working with, and that takes time and commitment to learn the languages at hand, which seems too difficult for you and many others to do!

This is not personal attack, this is what I see across the board from the uneducated, lazy programming masses!

Cheers

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@frogandtoad 

This is not personal attack, this is what I see across the board from the uneducated, lazy programming masses!

What is your educational background? Did you do formal courses in computer science? What is your occupation? Do you work in an area that involves programming? Your assumption is that because someone hasn't reached your peak of programming performance they are lazy. That is not necessarily the case. We all vary in our innate mental and physical attributes and some will always outshine the others even if the others may work just as hard, often many times harder, without being able to reached the same peak of performance.

Yes I am uneducated in that I have no formal education. What little I know I taught myself from books. I just found some things intensively interesting. However I am a hobbyist, an amateur. Why do you think I took an interest in Bill's video tutorials? If I was this super programming electronics person I would be making my own utube tutorials.

No I didn't keep up with all the latest. What I enjoyed doing worked fine with the "unimproved" C++.  I didn't have the time to keep up with the latest.  In my view it is all in the algorithms not the language.

I had to earn a living and had other serious life events to deal with. Not lazy, just time poor in that area which is just a hobby.

I am interested in learning some more about using C++ but I don't have the time to become a top gun C++ programmer and thus most of the time am forced to do it all the easy way if I want to achieve an outcome in a reasonable time.

Back before Windows I mainly programmed in Assembler.  I remember on the assembler forums how some looked down on those lazy people who used high level languages 🙂


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@robotbuilder @frogandtoad

It's time to abandon this dialog.

Please!

SteveG


   
THRandell reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

Posted by: @robotbuilder

@frogandtoad 

This is not personal attack, this is what I see across the board from the uneducated, lazy programming masses!

What is your educational background? Did you do formal courses in computer science? What is your occupation? Do you work in an area that involves programming? Your assumption is that because someone hasn't reached your peak of programming performance they are lazy. That is not necessarily the case. We all vary in our innate mental and physical attributes and some will always outshine the others even if the others may work just as hard, often many times harder, without being able to reached the same peak of performance.

Yes I am uneducated in that I have no formal education. What little I know I taught myself from books. I just found some things intensively interesting. However I am a hobbyist, an amateur. Why do you think I took an interest in Bill's video tutorials? If I was this super programming electronics person I would be making my own utube tutorials.

No I didn't keep up with all the latest. What I enjoyed doing worked fine with the "unimproved" C++.  I didn't have the time to keep up with the latest.  In my view it is all in the algorithms not the language.

I had to earn a living and had other serious life events to deal with. Not lazy, just time poor in that area which is just a hobby.

I am interested in learning some more about using C++ but I don't have the time to become a top gun C++ programmer and thus most of the time am forced to do it all the easy way if I want to achieve an outcome in a reasonable time.

Back before Windows I mainly programmed in Assembler.  I remember on the assembler forums how some looked down on those lazy people who used high level languages 🙂

 

Right... you're not willing to address the misinformation you provided, nor answer any of the questions I poised to you... that right there says it all to me.

Over and out!

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@codecage

Posted by: @codecage

@robotbuilder @frogandtoad

It's time to abandon this dialog.

Please!

Steve, mate we are having a passionate debate, nothing malice here!
Please stop intervening and trying to thwart freedom of speech.

Are no debates allowed here?
This kind of moderation is becoming absolutely ridiculous!

People in other threads are swearing at each other and you haven't said a word!

Thank you!

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@codecage 

Ok will do.  It was "Over and out!" from @frogandtoad anyway.

 


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@robotbuilder 

Thank you kind Sir!  All the best to you and yours for the Holidays.

SteveG


   
ReplyQuote
Page 3 / 3