Reputation: 481
Using crappy Eclipse Nios II which uses GCC 4. Included a file, which can be found as font8x8_basic.h online . I had warnings that I was indluding the file multiple times, so I was experimenting with adding key words const and extern, having only the inclusion in main to make it global. extern should not be used if an initialization is done, correct?
However, taking away const, gives me the warning of implicit constant conversion. Taking away const from the definition, doing clean, the error still remains!!?
In font8x8_basic.h
#ifndef FONT8x8_H_
#define FONT8x8_H_
char font8x8_basic[128][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul)
{ 0x00, 0x00, 0x0,...
In vga_util.h
#ifndef VGA_UTIL_H_
#define VGA_UTIL_H_
....
#include "font8x8_basic.h"
...
In sensor.h
#ifndef SENSOR_H_
#define SENSOR_H_
...
#include "vga_util.h"
In main.c
#include "vga_util.h"
#include "sensor.h"
My build log looks like this
05:27:22 **** Incremental Build of configuration Nios II for
project C_eng_job4 ****
make all
Info: Building ../C_eng_job4_bsp/
C:/altera_lite/16.0/nios2eds/bin/gnu/H-x86_64-mingw32/bin/make
--no-print-directory -C ../C_eng_job4_bsp/
[BSP build complete]
Info: Compiling main.c to obj/default/main.o
nios2-elf-gcc -xc -MP -MMD -c -I../C_eng_job4_bsp//HAL/inc
- I../C_eng_job4_bsp/ -I../C_eng_job4_bsp//drivers/inc -pipe -D__hal__
-DALT_NO_C_PLUS_PLUS -DALT_NO_INSTRUCTION_EMULATION -DALT_USE_SMALL_DRIVERS
-DSMALL_C_LIB -DALT_SINGLE_THREADED -O0 -g -Wall -Wpedantic -Werror
-mno-hw-div -mno-hw-mul -mno-hw-mulx -o obj/default/main.o main.c
In file included from vga_util.h:16:0,
from main.c:31:
font8x8_basic.h:69:25: error: overflow in implicit constant conversion
[- Werror=overflow]
{ 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*)
^
font8x8_basic.h:122:49: error: overflow in implicit constant conversion
[-Werror=overflow]
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_)
^
cc1.exe: all warnings being treated as errors
make: *** [obj/default/main.o] Error 1
Complete code can be seen here
Upvotes: 1
Views: 10117
Reputation: 20720
0xFF
does not fit in a char
if it is signed.
You should use unsigned char
for your array.
If that is not possible, then you can try to cast the value:
{ ..., (char) 0xFF, ... };
Then it should accept the number.
Also you could write the negative value. In case of 0xFF it's -1. A value between -128 and +127 will be accepted.
However, if you want that to work on any compiler, make sure to use signed char
and not just char
(or if you can unsigned char
) because various compilers see char
as signed (cl, the one you're using) and others as unsigned (gcc).
Upvotes: 4
Reputation: 401
sensor.c includes sensor.h which includes font8x8_basic.h. That gives one definition of the array font8x8_basic.
main.c includes vga_util.h which includes font8x8_basic.h. That gives one more definition of the array font8x8_basic.
Since you can have only one definition of an object in a program, you would need to make the array "extern" in the font8x8_basic.h file.
As for the compile warning since you are using initial values between 0x00 and 0xFF use unsigned char. If you want to keep the array type as char use values between -0x80 and 0x7F. Using a cast implies that you are forcing the value to meet the data type which isn't recommended.
Upvotes: 3