ATmega programming using Arduino Library - #2 [continuing]

Go To Last Post
87 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Lee: No, I will not publish the examples as avr-gcc code, ready for e.g. Atmel Studio. I firmly believe that you should learn C++ (and C for that matter), on a PC or similar. (Use an online compiler, or get one of the free C++ IDEs). Also, I have cut out things from the examples that are necessary for them to even compiler. I hinted about that above. Sorry, but you can not simply pick my examples above and build and run. I chose to do so to keep this as short as possible. I did not, e.g., wqnt to explain public/protected/private declarations so I threw them out before pasting my examples here. This is text to read, not code to run yourself.

 

@Jim: The arguments to main() is for coding with a PC as target (or, Mac in your case). See my reply to Lee just above for the rationale.

 

AND MOST IMPORTANT: This was the minimal "pedagogic journey" I could come up with to illustrate what virtual is about. I strongly argue that it is much more important ass a concept than ass a syntactic element in C++. BUT anyone I might have lured into the belief that this was actually a "Learn yourself C++ in three hours" deserve my apologies. The ambition was never anything more than trying to start from known C, illustrate superficially what is needed to know in order to superficially understand what virtual is about.

 

The rough tough fact is: Learning C++ will take time. It's not only that C++ is a large programming language (e.g. as compared to C that is regarded "minimal" by most connosieurs). It about adopting to "thinking object oriented". When I was exposed to OO the first time I has codded for 10 or 15 years. It took me a long time before I had cleansed myself from my C/Pascal thinking.

 

I speculate that the journey from C to object-oriented C++ actually is harder than going from assembler to C.

 

But the good thing is: You can use a C++ compiler, and utilize C++ code that someone else has written, without being an OO master. You still want to know, superficially, what goes on in that other persons code, and if it says virtual then the above is a shot at an explanation. If it also can serve as the first gentle (yes... gentle) introduction to OO and C++ then that a bonus.

 

I need to sleep now.. ;-)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem I have with the common "shapes" or "cars" examples always given for C++ is that it tells you nothing about how inheritance, polymorphism, encapsulation might actually be of any use when you program a real world example like an AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heat wave here, also. Will digest your latest post. Lots to chew on there. Then back to your first one, and try to integrate them together.

 

Huge gratitude!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heat wave here too. Is this "The day the Earth caught fire"?
.
Currently 10pm and I'm outside in shorts walking one of my Bengals as the house is like a furnace. Light just about going now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can give you the code below. It is the last example, complete. You can test it out e.g. here: http://www.cpp.sh/  At that site the compilation hangs from time to time when you try to run an example. Make sure you copy what you have in the editor window, then do a refresh of the page, and paste back what you copied. Nevertheless it seem to me to be a much better vehicle to learn C++ than to use Atmel Studio.

 

Whats in it that you have not seen?

 

1. The occurences of public. Each class has to start with e.g.

class Shape {
public:
 ...
}

This is not good design, but as I said I was not out to explain public/protected/private and the implications of it. That would need another two or  three posts...

 

Also, when inheriting you need a public there too.

class Circle : public Shape {
public:
   ...
}

And you need to start with (not a surprise, I hope):

#include <stdio.h>

 

COMPLETE CODE FOR THE LAST EXAMPLE:

#include <stdio.h>

class Shape {
public:
   double area;

   virtual void compute_area() = 0;

   void print_area() {
      printf("Area is %f\n", area);
   }
};

class Circle :  public Shape {
public:
   int radius;

   Circle(int a_radius) {
       radius = a_radius;
   }

   void compute_area() {
      area = radius * 2 * 3.1415;
   }
};

class Square : public Shape {
public:
   int side;

   Square(int a_side) {
       side = a_side;
   }

   void compute_area() {
      area = side * side;
   }
};

int main(int argc, char * argv[]) {
   // An array of pointers to Shapes
   Shape * my_shapes[3];
   // Fill it with different shapes
   my_shapes[0] = new Circle(15);
   my_shapes[1] = new Square(8);
   my_shapes[2] = new Circle(3);

   for (int i = 0; i<3; i++) {
       my_shapes[i]->compute_area();
       my_shapes[i]->print_area();
   }
}

Good night! (-:

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jun 19, 2017 - 09:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Crap, double post. Sorry..

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jun 19, 2017 - 09:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heatwave here is a mere 30C. But this is a temperate maritime area where this time of year, much above 25C is pretty rare.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The problem I have with the common "shapes" or "cars" examples always given for C++ is that it tells you nothing about how inheritance, polymorphism, encapsulation might actually be of any use when you program a real world example like an AVR.

For polymorphism I might agree. But encapsulation and inheritance are usable even in the smallest of applications IMO. And unless the compiler is crap, those two come with NO extra cost. You know my rant re this so I will digress.. ;-)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
@Lee: No, I will not publish the examples as avr-gcc code, ready for e.g. Atmel Studio. I firmly believe that you should learn C++ (and C for that matter), on a PC or similar.

 

OK, fair enough.  But let's say I've done some C++ and a fair amount of C#.  Now, given the thread is in the main MegaAVR and TinyAVR forum, you and Cliff appear to be proselytizing for the use on such platforms.  As such, I want to explore 

clawson wrote:

So those who would say "ah but C++ is large and bloaty compared to C" have once again been proven to have unfounded concerns. ;-)

...and your implied "defense":

JohanEkdahl wrote:

You just wait, Cliff. Soeone will come along with a splendidly ignorant argument..

 

Giving use of a generic/PC-based primer here -- what is the use if the examples cannot be built?  Indirectly, my "Hello World!" snipe enforces that.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To a significant degree Lee has a good point. Being able to build example code is critical for learning. And, for the best learning, one should have to work through some of those details, on ones own (small coin of the realm). At least at the start, that was what I was asking about. How do you deal with include files (and what is "needed", like avr/io.h). I think that was answered. Likewise, how to call C functions from C++ code. That was pretty well answered. (Thanks for both!) Johan's code in #58 does a lot more (thanks).  But, as critical as the concepts are, it is also critical to be able to write code that embodies the idea. And, have it run! That online tool is nice, but it seems like a parallel universe compared to Atmel Studio 7.

 

Johan, with that latest post of yours, I will have hours (and more hours) to digest and try. Thank you for your hard work and the supporting contributions that everyone else has put in to the sausage grinder. At that point, you don't even care whether or not the pig has lipstick!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Mon. Jun 19, 2017 - 10:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan -

 

You are a Prince! Maybe even a King!

Now let's be careful about that......or it's off with your headers....

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
My big question, though: how does one "instantiate" a class? I see code like:

RH_RF95 rf95;

Is that the instantiate statement?

Yes,  it says that there is a class RH_RF95 that is defined [most likely] in the file RH_RF95.h  An object named: rf95  of the class: RH_RF95 is being created (instantiated) in SRAM.

 

The source code for the class will be in the file: RH_RF95.cpp.  Arduino will look for this file in one of the three semi-secret folders where Arduino will only look for library source. 

The easiest to find is in the subfolder "libraries" in the  <Arduino_Sketches> folder.

 

The SRAM object is a collection of variables and function pointers.  The binary for the functions in class libraries that are called by the .ino file are stored in flash. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
C:\SysGCC\avr\bin>avr-nm lcd.elf | grep " T"
:
000001ba T _Z10lcd_clrscrv
000001a4 T _Z10lcd_gotoxyhh
00000206 T _Z10lcd_puts_pPKc
00000180 T _Z11lcd_commandh
000000d6 T _Z22wait_until_key_pressedv
00000192 T _Z8lcd_datah
000001c0 T _Z8lcd_homev
00000224 T _Z8lcd_inith

 

By the way, most of the gnu tools (nm, objdump) have a "-C" switch that will de-mangle names for you:

 

avr-nm -SC *.elf | more    

000001ea 00000042 t HardwareSerial::_tx_udr_empty_irq()
000001a2 0000001c t HardwareSerial::peek()
000001be 00000018 t HardwareSerial::available()
0000010e 00000016 t Print::print(char) [clone .constprop.10]
00000124 00000056 t Print::write(unsigned char const*, unsigned int)
0080023c 00000001 b SPIClass::initialized

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

int main(int argc, char * argv[], char *envp[])

well, envp is compiler-specific according to https://stackoverflow.com/questi...

and it is seldom used (I prefer getenv)

Only makes sense on a hosted OS of course.

Maybe an command line interpreter would be enough (keeping an array of chars ... and a list of {name, char[]}) if dynamic links are/were supported  -needs at least kind of disk... appleIIe had, without having an  full OS IIRC...-

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Examples can be built on a PC... (cygwin/ virtual box) or a xxPi...

Edited : with minor modifications -3 lines- , or -the last one- as it is...

 

BTW : for everything that is not avr -or other MCU- specific, using a PC, already soldered (avoids trouble shouting issues, which have nothing to do with learning -at least they should) makes things easier (and, anyway, one needs a PC /xxPi to cross compile & program). This avoids pluging a serial line (baudrate is never the right one), a LCD (sometimes, 3 lines and 25 chars would be very pleasant to verify math results are not absurd)

Last Edited: Tue. Jun 20, 2017 - 08:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

Johan -

 

You are a Prince! Maybe even a King!

Now let's be careful about that......or it's off with your headers....


Well, at least I'll go out with Class..
Seriously, in the conext given, the real kings where Kristen Nygaard and Ole-Johan Dahl. Google the names for more. Turns out that Object-Oriented Programming was a reality even long before K&R thought up the C programming language...

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Tue. Jun 20, 2017 - 07:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If one is a purist, the area of a circle il pi*radius*radius (is between the area of a sqare with size 2*r == 4*r*r (higher bound) , and the area of a smaller sqare, with size sqrt(2) r -> lower bound  area is 2*r*r.

 

 


private :
   void compute_area() {
      area = radius * radius * 3.1415;// pi is dimensionless, radius is meters -> area in m**2
   }
};

One can add rectangles, too,  initialized two ways :

both sizes are given;

only one size is given and one assumes it is a square (but it is not)

 

using an array of shapes, and computing (with old eyes, slow optical nerve and maybe a too warm brain) its number of elements is tedious and error prone (one never knowhs why the last element is not printed, if one adds an item) life seems easier on the long term with:

 

 Shape * mShapes[] = {new Circle(15),  new Square(8), new Rectangle(7,11),
      new Rectangle(22)};
    for (int i = 0; i<sizeof( mShapes) /sizeof mShapes[1];i++) {
       mShapes[i]->compute_area();
       mShapes[i]->print_area();
    }

Edited : tiny porion of typos removed; add dimension argument to know whether a formula is likely

Last Edited: Tue. Jun 20, 2017 - 11:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Johan,

   And to think I just purchased a C++ book from Amazon and could have saved a few $$$.

Maybe it will still be useful as reference........ 

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let me assure you that if that book is not crap I've covered just a few percent of it.

I repeat: C++ is a huge language.

What book, by the way?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Tue. Jun 20, 2017 - 08:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let me assure you that if that book is not crap I've covered just a few percent of it.

I repeat: C++ is a huge language.

 The usual problem with C++ books WRT embedded systems is that the books spend a lot of time talking about standard C++ libraries like C++ STL or Boost that are invaluable for solving Computer Science Problems on a PC, but generally need to be avoided on an embedded system (because they're heavily dependent on having lots of dynamically allocateable RAM.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scott meyers has some stuff on embedded c++ that is worth a read. I think he charges $20 or $30 bucks. He details the inner goings on like virtual method tables and static vs dynamic allocation so you can unserstand the 'cost' of using certain c++ features from an embedded perspective. I found it good value.

If you use the arduino core code as a guide, this should assist in using the applicable features of C++ for the pragmatic embedded programmer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I seem to recall that C++ does some bounds checking on array access. Does this still happen in the embedded world? Assuming that it does, does it slow down programs that are heavy array users (like transmit and receive buffers or uSD read/write buffers)? Does this happen on C code that is called from a C++ class?

 

What does it do on an attempted buffer over-run? Are there exceptions? If so, what does it do when one occurs? Do we need to write exception handlers?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Jun 21, 2017 - 01:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It only does bounds checking if you write code to do it. If you write a smart array object, then you can implement such features. Otherwise is just like C- no safety net.
Note: exceptions can be costly on an embedded system.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Kartman -

 

I could not imagine exception handling that was not costly, that is why I asked (especially pertinent if there is automatic bounds checking).

 

Thanks for the clarification.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forgot to mention : Virtual functions rely on tables of function pointers, known as v-tables. Although the function pointers are known at build time avr-gcc places them in SRAM rsther than flash memory. This is a deficiency of avr-gcc, not of C++ as a language. Approximate cost is:
One v-table per class (not object) that has virtual functions. Size of table is number of virtual functions times size of function pointer (16 bits?).

 

EDIT: Addendum: Each object also bears with it a cost if using virtual functions - a pointer to the applicable v-table. But this is so in any implementation and is not a deficiency. (And you can now infer what happens when a virtual function is used: De-reference the objects v-table pointer to get to the table. Then de-reference the applicable function pointer in the v-table, doing a call to the function itself. I.e. a double indirection.  Actually, the "as-if" rule applies here. An implementation can chose another implementation as long as it is functionally equivalent to this - but I have yet to see a compiler that does not actually do it this way..)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Thu. Jun 22, 2017 - 03:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Run into a problem referring to the Fleury  TWI/I2C library. Following Johan's suggestions up in #11, I wrote this

 

void OREi2c::begin( void ) {

	PRR &= ~(1<<PRTWI);  //make sure power is on

	#ifdef __cplusplus
	extern "C" {
	#endif

	i2c_init(void);	//Fleury

	#ifdef __cplusplus
	}
	#endif

} //end OREi2c::begin( void )

With the corresponding header referenced by

 

 extern "C" {
 #include "i2cmaster.h"  //fleury header
 }

At the top of the file with the first code. The class declaration is (not much there, yet)

 

class OREi2c {

	public:

	void begin( );

};	

But, I get an error, pointing to the extern "C" expression, with the cursor immediately before "C", saying:

 

Severity

Code

Description

Project

File

Line

Error

 

expected unqualified-id before string constant

ORE_Test

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_i2c.cpp

70

 

 And the actual compiler output says:

 

        ../ArduinoCompatibility/ORE_i2c.cpp: In member function 'void OREi2c::begin()':

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_i2c.cpp(70,9): error: expected unqualified-id before string constant

          extern "C" {

                 ^

        make: *** [ORE_i2c.o] Error 1

I really don't know what "qualified id" refers to. Could use some help, here. This is an attempt to provide a CPP "wrapper" for the Fleury I2C library.

 

Note: I realize that I CAN just copy the guts of various Fleury TWI/I2C functions into normal corresponding C++ functions. Would prefer not to do that to maintain as tight a chain of attribution as possible. But, if push comes to shove, that is what I will do.

 

Thanks

Jim 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Jul 16, 2017 - 06:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void OREi2c::begin( void ) {

	PRR &= ~(1<<PRTWI);  //make sure power is on

	i2c_init(void);	//Fleury


} //end OREi2c::begin( void )

The extern "C" is so the compiler 'knows' about the C functions and handle the naming correctly. It makes no sense inside the method - only for the header file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim!

 

As Kartman points out, you the extern "C" is only needed at the declaration of the functions (i.e. when including the header file). Think of this in the same way ass if you e.g. declare something to be const or static or... You only tell once, at the declaration or definition. Not every time you reference something.

 

Once the compiler has been told that a function is using "C linkage" it will have that noted/remembered for the rest of the compilation unit, and will handle calls to it accordingly. And telling is at the point of declaration.

 

(Side-comment: And even if this was allowed or required at the point of call, your #idfef __cplusplus guards would be un-necessary. Since they are in a .cpp file, and that can only be compiled by a C++ compiler, __cplusplus will always be defined. (-: )

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I make that change, I now get an error:

 

Severity

Code

Description

Project

File

Line

Error

 

expected primary-expression before 'void'

ORE_Test

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_i2c.cpp

69

 

 In the line: 

i2c_init(void);	//Fleury

twimaster.c HAS been added to the project and i2cmaster.h IS being recognized (eg, no message about not being found).

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Jul 16, 2017 - 03:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

Read your K&R.
It show the syntax for executable statements. Compared to function declarationss / definitions.

David.

Last Edited: Sun. Jul 16, 2017 - 04:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim!

ka7ehk wrote:
 In the line: 

i2c_init(void); //Fleury

Similar mistake as previously. the "void" goes into definitions/declarations of the function only. A call to this function, that takes no parameters, is simply

i2c_init();

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm, missed learning that detail, somehow. Or,  something! I THINK I was able to use void in C calls, but I am not so sure, now. Now etched in the neural network!

 

That was the problem.

 

Thanks

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Jul 16, 2017 - 07:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Hmm, missed learning that detail, somehow. Or,  something! I THINK I was able to use void in C calls, but I am not so sure, now.

I'm sure: You've never been able to do that.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oooops! Sorry I missed the void as well.

 

I'm working on a sizeable (20+ classes) c++ embedded project at the moment and in my cutting and pasting I've made the same mistake myself. I'm using IAR and unfortunately their IDE is rather dated and doesn't provide a lot of the helper features the new IDEs have like online syntax checking etc. Eventually it will annoy me enough to look at something more modern.

 

I've currently made all my classes statically allocated, but my code is getting a bit messy with handing around global references, so I dare say I'll have some dynamically allocated ones and I'll have to keep an eye on the heap. Since I will only allocate once, I won't have issues with the heap fragmenting.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
When I make that change, I now get an error:
And once again your posts shows the futility of the "Error List" in Studio! These days avr-gcc goes to some length to show you exactly where an error is located:

C:\SysGCC\avr\bin>type avr.cpp
#include <avr/io.h>

class someClass {
public:
        foo();
};

int main(void)
{
        someClass bar;
        bar.foo(void);
        while (1);
}
C:\SysGCC\avr\bin>avr-gcc -mmcu=atmega16 -Os avr.cpp -o avr.elf
avr.cpp:5:6: error: ISO C++ forbids declaration of 'foo' with no type [-fpermissive]
  foo();
      ^
avr.cpp: In function 'int main()':
avr.cpp:11:10: error: expected primary-expression before 'void'
  bar.foo(void);
          ^

Notice how it has cleverly placed the '^' to show exactly where in that line it has detected the error? Then Studio eats this up and spits it out as:

 

Severity

Code

Description

Project

File

Line

Error

 

expected primary-expression before 'void'

ORE_Test

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_i2c.cpp

69

 

In a report like that it tells you nothing about which column the error was in or even uses ^ to show where that is exactly. It just tells you it's line 69.

 

Oh and it will often rearrange the list of errors. On the whole the only one that ever matters is the first one.

 

For all these reasons I would switch to Output and look at the real build output - identify the location of the first error and read everything the compiler has to say about it.

Pages