2

I have an Atollic True Studio (Eclipse) project with many files. I have noticed that the project compiles despite the fact that one of those files contains a function call with arguments where the corresponding function declaration and definition have no parameters.

I have tried adding additional arguments to function calls in other files and function calls in the same file of functions which have been defined in other files and they give the expected "too many arguments to function" error.

I have tried replacing Eclipse's internal builder against a makefile and the arm-atollic-eabi-gcc compiler against arm-none-eabi-gcc but the behaviour stays the same: no error message for that function call.

I have managed to break it down to the following MWE:

main.c:

#include "foo.h"

int main(void)
{
    foo(0);
}

foo.h:

#ifndef _FOO_H_
#define _FOO_H_

void foo(int);

#endif /* _FOO_H_ */

foo.c:

#include "foo.h"

void fun();

void foo(int data)
{
    fun(42);  // why is this no error?
}

void fun()
{
    volatile static int i = 0;
    i++;
}

Makefile:

#http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
#https://www.gnu.org/software/make/manual/make.html

CC=arm-none-eabi-gcc
LSCRIPT=STM32F765VG_FLASH.ld

# $ find Debug -name "*.o"
OBJ =
OBJ += Debug/foo.o
OBJ += Debug/main.o

# $ find . -name "*.h"
DEPS = 
DEPS += foo.h


## ----- Create Directories -----
OBJDIRS:=$(dir $(OBJ))

# dummy variable to avoid target given more than once error
# https://stackoverflow.com/a/50332332
DUMMY:=$(shell mkdir --parents $(OBJDIRS))


## ----- Assembler -----
#   $(CC) -c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -g -Wa,--no-warn -x assembler-with-cpp -specs=nano.specs

# ----- Compiler -----
Debug/%.o: %.c $(DEPS)
    $(CC)   -o $@ $<   -c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -std=gnu11 '-D__weak=__attribute__((weak))' '-D__packed=__attribute__((__packed__))' -DUSE_HAL_DRIVER -DSTM32F765xx -Og -ffunction-sections -fdata-sections -g -fstack-usage -Wall -specs=nano.specs

Debug/%.o: %.s $(DEPS)
    $(CC)   -o $@ $<   -c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -std=gnu11 '-D__weak=__attribute__((weak))' '-D__packed=__attribute__((__packed__))' -DUSE_HAL_DRIVER -DSTM32F765xx -Og -ffunction-sections -fdata-sections -g -fstack-usage -Wall -specs=nano.specs

# ----- Linker -----
Debug/CMCU_SW2.elf: $(OBJ)
    $(CC)  -o $@ $^     -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -T"$(LSCRIPT)" -specs=nosys.specs -static "-Wl,-Map=$(BuildArtifactFileBaseName).map" -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x80 -Wl,--start-group -lc -lm -Wl,--end-group -specs=nano.specs
jakun
  • 624
  • 5
  • 13
  • 7
    `void fun();` means a function that returns nothing _and can take any number of parameters_. To declare it takes _no_ parameters declare as `void fun(void);` – Paul Ogilvie May 22 '20 at 15:55
  • Does this answer your question? [GCC behaviour when calling a function with too many arguments](https://stackoverflow.com/questions/24700552/gcc-behaviour-when-calling-a-function-with-too-many-arguments) – zgyarmati May 22 '20 at 15:56

0 Answers0