Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   C or C++ (http://www.chiefdelphi.com/forums/showthread.php?t=49961)

Alan Anderson 14-11-2006 22:43

Re: C or C++
 
Quote:

Originally Posted by Rickertsen2
I think most of us would agree that we would rather have the flexibility and added features of C++, particularly object oriented-ness.

Why? What particular itch would be scratched by having OO in your robot-programming toolkit?
Quote:

Any problem that can be solved in C++ can be solved in C.
That's obviously true -- because the first implementation of a C++ compiler was as a preprocessor that produced straight C code. If you want to use C++ to program your robot, just get a copy of the old AT&T Cfront program. :P

Kevin Sevcik 14-11-2006 23:09

Re: C or C++
 
Quote:

Originally Posted by Alan Anderson
Why? What particular itch would be scratched by having OO in your robot-programming toolkit?

Well it would let you use << instead of printf's. Heck you could overload << operator to output motor values or set the target of a PID loop or other mostly useless but amusing things, I suppose.

TimCraig 14-11-2006 23:17

Re: C or C++
 
It's amazing the misconceptions that have been posted here about the differences between C and C++. C++ code doesn't have to be bloated compared to equivalent C code. When using the advanced features you do have to know what you're doing if you don't want to pay a size or performance penalty.

I used C for years and then moved to C++. Moving back to C was an extreme shock. Having to jump through hoops to do reasonable encapsulation and using funky naming conventions to keep the code organized and readable is a roaring pain. The lack of proper const types is inhibiting.

Some here seem to think that using C++ entails a lot of new and free calls to create and destroy objects. If your C code isn't using a lot of malloc and free calls, there will be no difference. And for a FIRST robot you really don't need any dynamic memory allocation.

C++ is a much better language and with proper use can even produce smaller, faster code than C. Not to mention if the code is properly written, it's easier to understand, maintain, and more robust.

Gdeaver 15-11-2006 08:13

Re: C or C++
 
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.

Alan Anderson 15-11-2006 08:21

Re: C or C++
 
Quote:

Originally Posted by Kevin Sevcik
Quote:

Originally Posted by Alan Anderson
Why? What particular itch would be scratched by having OO in your robot-programming toolkit?

Well it would let you use << instead of printf's. Heck you could overload << operator to output motor values or set the target of a PID loop or other mostly useless but amusing things, I suppose.

I was asking about Object Oriented, not Operator Overloading. My question is this: how would object-oriented programming be useful in programming a FIRST robot?

Modular programming is obviously a good thing, but I don't really see a good use for classes and inheritance and polymorphism and such.

Dave Flowerday 15-11-2006 08:30

Re: C or C++
 
Quote:

Originally Posted by Gdeaver
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.

Actually C++ is quickly gaining in popularity in the embedded world. The last project I worked on at Motorola was almost entirely C++ code running on an embedded control board under the pSOS and OSE RTOSes.

Bongle 15-11-2006 10:09

Re: C or C++
 
Quote:

Originally Posted by efoote868
Too bad its not so easy to describe #define, or any other preprocessors to them :(.

For #define, I told the kids on my team it is essentially the same as a find-replace on your code before it actually gets compiled. That explanation is good enough for what we used it for (#define leftMotor1 pwm01).

TimCraig 15-11-2006 12:48

Re: C or C++
 
Quote:

Originally Posted by Gdeaver
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.

Object oriented languages aren't any more asynchronous than purely procedural languages. If you're talking about the message passing paradigm, that's just OO speak for function calls.

That said, however, most microcontroller programs have to deal with asynchronous events.

chris31 15-11-2006 15:40

Re: C or C++
 
http://www.virginiafirst.org/workshop_info.shtml

I figure it just a typo but look at "Beginning Programming - part 1". Maybe they know something we dont know. Im pretty sure its a typo though.

X-Istence 15-11-2006 15:46

Re: C or C++
 
I screw it all. Let's go back to the PBASIC boards from a few years ago.

chris31 15-11-2006 18:47

Re: C or C++
 
Quote:

Originally Posted by X-Istence
I screw it all. Let's go back to the PBASIC boards from a few years ago.

LOL. I have never used to PBASIC boards but I like the C ones just fine.

Astronouth7303 15-11-2006 21:34

Re: C or C++
 
I'm going to try to clarify somethings about using OOP on the current breed of controllers.

Using any kind of memory management on the PIC18s would incur a performance penalty in terms of pointers, indirect addressing, management overhead, etc. I don't care how few malloc()/free() calls there are; it only takes one. In order to perform indirect addressing, you have to copy the pointer to a special register. Every dereference requires this, on a byte-by-byte basis. I'm not even sure you can perform an indirect function call. (Remember, code is stored seperate from data.)

I agree that using OOP principles is a Good Thing(tm). But the limits of the PIC18 processors are such that full-blown OOP (or even just objects) as it is normally implemented is impractical.


All times are GMT -5. The time now is 18:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi