For enhancing portability I am attempting to modify this inherited piece of fortran and c software to change from passing char *'s to fortran from a c function, and instead initializing character variables (in the c code) stored in common on the fortran side.
If you have a better way, please suggest. I thought this might be the best way to avoid all of the portability issues that I have come across. Some systems pass an int at the end of the argument list, some long ints, it core dumps on the sun at the call, seems to be OK on linux, but in general the thing is a constant source of pain; hence, the reason I'm trying to change it.
I thought that if I created a struct declared as extern with the same name as the common block in the fortran code, that I could then initialize the character variables in fortran common from within the c code via the struct of the same name. This works for int's, floats, etc..
Don't ask or suggest doing it on the fortran side. I wish I could. This thing also uses lex and yacc to parse the input deck, and the initialization of all the variables is done via lex, yacc and c. I know nothing of lex and yacc. I wouldn't even attempt to change the parsing over to fortran.
So initialization of the variables from the input deck has to be done within c, and I have to then initialize fortran common. As I said it's working fine for int's and floats, etc. The original author elected to not do this for strings, hence, the reason I'm asking this question here.
THe compiler is accepting it, and I can print out the values of the strings on the c side, but when I go to the fortran side they have garbage in them. So, as an example, say I have a struct named 's'. And a common of the same name on the fortran side. On the fortran side I have a character array of a large size, say string. ON the c side the 's' struct has string as a member and is declared as a char *.
On the c side I do
c.string = something from the lex/yacc parser.
I printf it out and can see that it is set correctly.
But on the fortran side, if I print out the value of string it's got garbage.
Anyone have any ideas, or have a better suggestion?
Thanks very much,