Clicky

Fortran Wiki
Question (Rev #3, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #2 to #3: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

I use the jsu_readline, probably from ‘urbanjost’, found many years ago somewhere in the internet. It works fine for a long time, still with some warnings compiling the subroutine FCreadline.c. Since debian 13 gfortran (gcc version 14.2.0) it rejects this subroutine as erroneous.

I found this subroutine in the Fortran Wiki as iso_readline(3f). Compiling it results in the same error (the comment marker in the 6th line of this example should read read / instead of / ?):

fcreadline.c:24:1: error: return type defaults to ‘int’ [-Wimplicit-int] 24 | FCreadline(int len, charmyline, char prompt[]){ | ^~~~~~~~~~ My work around: using the object file FCreadline.o from debian12, which is not as it should work.

Is there a corrected ersion available? Thanks in advance.

The message is indicating the return value needs explicitly declared, or in this case, needs set to void. Place the word "void" in front of FCreadline. I am not at a place were I can verify that is all that is needed, but I will change the entry found here on the Fortran wiki accordingly. https://github.com/urbanjost/general-purpose-fortran contains the latest version of this and a few thousand other routines as well.

(追記) (追記ここまで)(追記)

Reply:

(追記ここまで)
(追記) (追記ここまで)(追記)

Well, ‘void’ did the job to get rif of the error flag, the warnings still arose. With the help of a friend (Andreas) we were able to loacate two statements in ‘FCreadline.c’, which need to be changed (see below). The ‘testit’ example works as well as my Fortran applications.

(追記ここまで)
(追記) (追記ここまで)(追記)

I enclose the complete function. German comments denote the modifications. Thank you.

(追記ここまで)
(追記) (追記ここまで)(追記)

—————————– 8>< ——————————————————— /* @(#) Fortran-callable C routine that calls readline(3c) The Fortran routine can use the f2003 ISO_C_BINDING module to do this in a portable manner. assumes you have the GNU readline library libreadline.a available /

(追記ここまで)
(追記) (追記ここまで)(追記)

include <stdlib></stdlib>

(追記ここまで)
(追記) (追記ここまで)(追記)

include <unistd></unistd>

(追記ここまで)
(追記) (追記ここまで)(追記)

include <stdio></stdio>

(追記ここまで)
(追記) (追記ここまで)(追記)

include <string></string>

(追記ここまで)
(追記) (追記ここまで)(追記)

include <readline></readline>/readline.h>

(追記ここまで)
(追記) (追記ここまで)(追記)

include <readline></readline>/history.h>

(追記ここまで)
(追記) (追記ここまで)(追記)

/* ——————————————————————— / void show_history_list() { HISTORY_STATEstate = history_get_history_state(); int i; printf("History list now:\n"); for (i=0; i < state->length; i++) { printf("%d: ‘%s’%s\n", i, state->entries[i]->line, (i == state->offset? "":"")); }
} /
————————————————————————– / // void FCreadline(intlen, char myline, char prompt[]){ void FCreadline(int len, charmyline, const char prompt){ / @(#)FCreadline.sh return line from readline(3c) to Fortran. John S. Urban, 20100323

(追記ここまで)
(追記) (追記ここまで)(追記)

Simple procedure that uses readline in "normal" (i.e. non-callback) mode.

(追記ここまで)
(追記) (追記ここまで)(追記)

len – number of characters in argument "myline" myline – Fortran CHARACTER variable to receive the line read by readline(3c) prompt – prompt string to precede read

(追記ここまで)
(追記) (追記ここまで)(追記)

/ / readline(3c) will return the read line to this pointer / charline; /* counter for padding returned line with spaces / int i;

(追記ここまで)
(追記) (追記ここまで)(追記)

using_history();
/* use readline(3c) to read a line of input in edit mode / line=readline(prompt); add_history(line);

(追記ここまで)
(追記) (追記ここまで)(追記)

/* if the "h" command is on a line by itself show history / if(strcmp(line,"h")==0){ show_history_list(); }

(追記ここまで)
(追記) (追記ここまで)(追記)

/* copy line returned by readline(3c) to MYLINE up to length of MYLINE / // ersetzt: strncpy(myline,line,(size_t)len); strncpy(myline,line,(size_t)len);

(追記ここまで)
(追記) (追記ここまで)(追記)

/* starting with null, pad with spaces to end / // ersetzt: for(i=strlen(line);i<(int)len;i++){ for(i=strlen(line);i

(追記ここまで)
(追記) (追記ここまで)(追記)

/* free memory used to return line from readline(3c) / if (line) // neu: als sicherheit wenn readline mal // NULL zurückgeben sollte. Dann würde ohne diese Abfrage // der Aufruf von free() crashen. free(line);
}

(追記ここまで)
Revision from August 29, 2025 15:57:20 by Wolf-Rainer?
Forward in time (to current) | Back in time (2 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Questions

AltStyle によって変換されたページ (->オリジナル) /