Cannot be an initialiser

It’s been a while since I posted on here; my STELCOR code has come on leaps and bounds and works well (given I still need to add some stellar evolutionary controls for massive stars).

Anyway, I have an f90 module file called eos_calcutions that begins with:

module eos_calculations

    use stellar_values,            only: DP, ONE5TH
    
    private
    public  :: calculate_eostab
    
contains
    
        function calculate_eostab(gas_pressure, temperature, hydrogen_abundance, helium_abundance, maximum_helium)      &
            result (eos_test)
      
        use zones,                only:lunit
        
        implicit none
        
        real(DP), intent(in)    :: gas_pressure, helium_abundance, hydrogen_abundance, maximum_helium, temperature
        real(DP)                :: eos_test(5)

The point of interest is the result variable of eos_test

It next appears at the conclusion of the function…

            eos_test(i) = dx1 * (ds1 * xx(1) + ds2 * xx(3)) + dx2 * (ds1 * xx(2) + ds2 * xx(4))
        end do

    end function calculate_eostab

end module eos_calculations

When I compile using a series of flags for testing purposes I get:

garynewport@Garys-MacBook-Air 2025.11.11 % make test 
/Applications/Xcode.app/Contents/Developer/usr/bin/make clean
rm -f modules.o general_calculations.o eos_calculations.o opacity_calculations.o nabla_calculations.o nuclear_reactions.o stelcor.o process_evolution.o dummymain.o *.mod
rm -rf mod_folder
/Applications/Xcode.app/Contents/Developer/usr/bin/make FLAGS="-g -O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace -fno-unsafe-math-optimizations -finit-real=snan -Wall -Wsurprising -Jmod_folder" all
rm -rf M0.5 M1 M2 M4 M8 M16 M32 M64
gfortran -g -O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace -fno-unsafe-math-optimizations -finit-real=snan -Wall -Wsurprising -Jmod_folder -c modules.f90 -o modules.o
gfortran -g -O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace -fno-unsafe-math-optimizations -finit-real=snan -Wall -Wsurprising -Jmod_folder -c general_calculations.f90 -o general_calculations.o
gfortran -g -O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace -fno-unsafe-math-optimizations -finit-real=snan -Wall -Wsurprising -Jmod_folder -c eos_calculations.f90 -o eos_calculations.o
eos_calculations.f90:11:29:

   11 |             result (eos_test)
      |                             1
Error: Function result 'eos_test' at (1) cannot have an initializer
make[1]: *** [eos_calculations.o] Error 1
make: *** [test] Error 2

Yet, if I run a simple compile everything is fine:

garynewport@Garys-MacBook-Air 2025.11.11 % make
rm -rf M0.5 M1 M2 M4 M8 M16 M32 M64
gfortran -O -Jmod_folder -c eos_calculations.f90 -o eos_calculations.o
gfortran -O -Jmod_folder -c opacity_calculations.f90 -o opacity_calculations.o
gfortran -O -Jmod_folder -c nabla_calculations.f90 -o nabla_calculations.o
gfortran -O -Jmod_folder -c nuclear_reactions.f90 -o nuclear_reactions.o
gfortran -O -Jmod_folder -c stelcor.f90 -o stelcor.o
gfortran -O -Jmod_folder -c process_evolution.f90 -o process_evolution.o
gfortran -O -Jmod_folder -c dummymain.f90 -o dummymain.o
gfortran -O -Jmod_folder modules.o general_calculations.o eos_calculations.o opacity_calculations.o nabla_calculations.o nuclear_reactions.o stelcor.o process_evolution.o dummymain.o -o dummymain
# Delete old directories
rm -rf M0.5 M1 M2 M4 M8 M16 M32 M64
# Create directories
mkdir -p M0.5 M1 M2 M4 M8 M16 M32 M64
# Copy files into each directory
for d in M0.5 M1 M2 M4 M8 M16 M32 M64; do \
		cp cool.opac dummymain eospointer eostable stelcor.inp GN93hz hel.cond hyd.cond stelcor.mod.keep $d/ ; \
		[ -d dummymain.dSYM ] && cp -R dummymain.dSYM $d/ || true ; \
		mv $d/stelcor.mod.keep $d/stelcor.mod ; \
	done
rm -f modules.o general_calculations.o eos_calculations.o opacity_calculations.o nabla_calculations.o nuclear_reactions.o stelcor.o process_evolution.o dummymain.o *.mod
rm -rf mod_folder
rm -f dummymain

It is called eos_test because it was originally called eos, which does exist elsewhere and I wondered if I was getting a conflict. I renamed it eos_values and got the same error (I had cleared out all .o files, etc to ensure it wasn’t arising from an old result).

I found in another module that I had also used eos_values, though this was not actually being used anywhere. Just to ensure there was no conflict with this either I used eos_test. I have checked all files and there is no reference to eos_test outside of this function.

I cannot identify where the error is arising and why it is arising only when I run the make test, which uses these flags…

TFLAGS  = -g -O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace -fno-unsafe-math-optimizations -finit-real=snan -Wall -Wsurprising -Jmod_folder

Any ideas/suggestions?

No obvious sign of error in the MWE mimicking your interface: Compiler Explorer

Two further comments:

  • you are not using implicit none,
  • did you search for eos_test with grep: grep -RIn "eos_test" /path/to/folder?
1 Like

The only thing I can think of is that -finit-real=snan flag. Although the options have “init” in the name, this is nothing to do with initialization as understood in Fortran. It is rather a directive to the code generator to insert assignments at the top of the executable block. But it could be that some compiler internals get confused and cause it to emit that non-sensical error message. Try without the flag.

1 Like

You say I am not using implicit none, yet it is just below the use zones line; am I misunderstanding here?
Yes, I am confident it does not appear elsewhere within this folder. :slight_smile:

Yes, I recognised this as the flag that is generating the warning, just not too sure why!

I removed it and it’s fine. As stated, the non-test make works fine - just don’t like having things like this residing in my code. Assuming it’s a compiler glitch.

Thank you. :slight_smile: