Quadruple Dutch warning

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I imported a project into AS7 and after some fiddling got it to compile and run correctly, however I get 3 warning I would like to get rid of.

 

 

One of the changes I had to do was to add "const" to the fonts and had to change the line above the warning, so how do I get rid of that warning?

 

The other 2 I understand but don't know what to do about the warning.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Is double Dutch not enough?

 

If you assign a "const" pointer to a non const pointer you get a warning, because the non-const has now the potential to change a constant.

So it seems you also have to change "FontPointer" as pointing to constant data.

Alternatively you may get away with compiling under an older C standard.

 

The "set but not used" warning seems clear.

It might be some left over from a "previous" revision of the code, in which case you can delete / comment out line 103 in Yamaha_PS620_d_Graphics.c if it has no other side affects, or there might be some other reason why "bx" and "ay" are not used after they are being set. So start with a search for those variables.

Alternatively you can simply surpress the warning by adding the string between square brackets to the compiler command line.

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Sun. Apr 22, 2018 - 10:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you really mean to drop const on line 41 ('pointer is but 'FontPointer' isn't ) then apply a "( unsigned char *)" cast to pointer.

 

As for the other one, show line 103

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

"Set but not used" warning: Why are you setting a value, if you're not using it? To fix the warning you must answer the question.

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

So I changed line 41 (maybe I got this wrong?)

/* _____PUBLIC FUNCTIONS_____________________________________________________ */
void LcdFont(const unsigned char *pointer)
{
//	FontPointer = pointer;

	FontPointer = unsigned char *pointer

	FontWidth 	= pgm_read_byte_near(&FontPointer[2]);
	FontHeight	= pgm_read_byte_near(&FontPointer[3]);
}

and commented out line 103

 


	signed int a, b, P;
//	signed int bx, ay;		//Commented out JS 23/04/2018

// adjust size

and now I get!!

 

 

Why are you setting a value, if you're not using it?

I have no idea, it's not my code! It's a graphics library I came across a few years ago and it has been working well and I don't get any warnings on AS4.18, AS7 is complaining. smiley

 

so ay and bx ARE being used here

// draw border
	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;

I know, I know and I agree:some people should not be allowed anywhere near a C compiler.....cheeky

 

EDIT I fixed the ay,bx warning. They are not being used inside THAT function but used in others, they are local variables.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. Apr 22, 2018 - 09:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This gets rid of the last warning

    const unsigned char *FontPointer = pointer;

but also gets rid of the fonts! crying Quadruple Dutch is not enough.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I have trouble reading the screenshot code, even after saving them and using a viewer.

Still have no idea how anyone located line 41.

 

Assigned but not used suggest you should get rid of the assignment AND the declaration.

FontPointer = unsigned char *pointer
is not syntactically correct.

Casting involves parentheses: (unsigned char *)pointer .

Casting might or might not be what you want.

I gather FontPointer is pointer to non-const char.
pointer is pointer to const char.
Why and why?  Reasons matter.
My guess is that one is wrong.
Fix that one.

One possibility is that someone wrote a lot of
code without using const when he should have.
In such a case, you might need to decide
whether a global fix is worth the effort.
If not, you might be stuck with casting away const.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

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

js wrote:

 

so ay and bx ARE being used here

// draw border
	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;

I know, I know and I agree:some people should not be allowed anywhere near a C compiler.....cheeky

 

no they are not John, here the are set ( the set part of the "are set but not being used")

you also need to comment out these to lines as you have removed the declaration of the variables, but now you want to set something that is not going to be used.

in other words, waste SRAM locations and instructions in the process.

 

edit: qoute went into garbage mode had to do a litle restauration/repair on it

Last Edited: Mon. Apr 23, 2018 - 05:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

    FontPointer = (unsigned char *) pointer; fixed it, thank you.

 

Still have no idea how anyone located line 41.

the first line in the error list of the screen shot shows line 41 on the R/H side of the screen.

One possibility is that someone wrote a lot of
code without using const when he should have.

The old way of using PROGMEM  (edit was EEMEM) did not require const, AS7 enforces this I think.

 

Anyway no more warnings, I'm happy. laugh

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Mon. Apr 23, 2018 - 10:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you also need to comment out these to lines as you have removed the declaration of the variables,

 

The last line in #5 (EDIT) shows the fix.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	FontPointer = unsigned char *pointer

was supposed to be:

	FontPointer = (unsigned char *)pointer

What I was suggesting is that when you have two pointers of different types (which causes the compiler to say "you could have problems because these aren't quite the same" as you see) you can use a cast to say "before this assignment is made take the value being delivered and assume it is of this type instead" - which is what the typecast achieves.

 

To be honest, though, when the compiler warns about modifiers like "const" or "volatile" being dropped at the point of usage it's probably making a very valid point. Why isn't the "const"ness carried all the way through (these days "const" may well also be linked to "__flash" too).

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

Edit: One of those days I have trouble thinking straight. I thin I say the same thing 3x in this post but right now I get confused in writing it down in a coherent logical way.

I hope this post still adds something usefull...

 

js wrote:
One possibility is that someone wrote a lot of code without using const when he should have.
My Idea also.

I'm not sure about the details, but once an object is declared as being a constant, then all pointers to that object must also be declared as pointers to a constant object, because else the pointers have the possibilitiy to change the object and constant object can not (by defenition) be changed.

 

Normally it is not allowed to to use a pointer to a non constant object to point to an immutable constant object.

Therefore const has the tendency to progress through the code.

With casts you override this default strict pointer type checking, and you did just that. Edited this post after reading chapter 8.4.1 of:

http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html

 

Adding const where it should be used in the code is farily straight forward while writing the code, but adding it in retrospect can be ... a bit confusing.

Instead of using the cast it would be better to declare FointPointer as a pointer to const also.

 

Note:

js wrote:
The old way of using EEMEM did not require const, AS7 enforces this I think.
In this case we're talking about a font array in pgm memory, not een EEprom. Flash normally can not be written to in AVR's.

 

Edit:

After posting I saw clawson posted also, with largely the same intent: Constants can not be changed and it is beter / neater to keep the chain of const and not using casts, and in this case it can be done by making FointPointer point to a const array, but this is just the next step because you may trigger warnings / errors on the other uses of FointPointer, where it also should have been declared const. Your main goal is probably to get your Yamaha LCD going and not improvement of an old LCD library.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Mon. Apr 23, 2018 - 10:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be honest, as this is "new" code I would not just use "const" but "const __flash" and pass that around. Then drop all the use of pgm_read_XXX(). Everything related to the use of the fixed font data in flash would all then be "const __flash type" and the pointers "const __flash type *"

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

js wrote:
FontPointer = (unsigned char *) pointer; fixed it, thank you. Still have no idea how anyone located line 41. the first line in the error list of the screen shot shows line 41 on the R/H side of the screen.
Saw that.  The difficulty was finding line 41 in the code.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

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

In this case we're talking about a font array in pgm memory, not een EEprom. Flash normally can not be written to in AVR's.

Sorry a slip of the fingers, I meant PROGMEM. And nothing is being WRITTEN to the AVR, just reading font's and graphics from flash.

as this is "new" code I would not just use "const" but "const __flash"

The library is very old code, some of the files go back to 2009 at least on my HDD, it could be older, and I don't want to mess around with that because it works and I will surely make a mess of things if I attempt to change it. Cursed pointers! cheeky

 

Anyway it ain't broken anymore so no need to fix it. smiley

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

There was a load of ASF code where things which should have been const weren't ...

 

angry

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...