albert@emx.utexas.edu (Lo Mau Tout) (10/03/90)
In ANSI C, the prototype of fopen is supposed to be FILE *fopen ( const char *filename, const char *mode ); Does that mean I cannot specify in the position of the first parameter a filename[i], where i is an integer, of type char *filename[] ?
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/04/90)
In article <37852@ut-emx.uucp> albert@emx.utexas.edu (Lo Mau Tout) writes: >In ANSI C, the prototype of fopen is supposed to be >FILE *fopen ( const char *filename, const char *mode ); >Does that mean I cannot specify in the position of the first parameter >a filename[i], where i is an integer, of type char *filename[] ? Sure you can. That direction of qualification is compatible. The other, where you would try feeding a pointer to const to a function that is expecting to be able to scribble on what is pointed to, would not be allowed.
alex@bilver.UUCP (Alex Matulich) (10/06/90)
In article <37852@ut-emx.uucp> albert@emx.utexas.edu (Lo Mau Tout) writes: >FILE *fopen ( const char *filename, const char *mode ); > >Does that mean I cannot specify in the position of the first parameter >a filename[i], where i is an integer, of type char *filename[] ? As I understand it, the "const char *" means that fopen() cannot modify the pointer in any way. It's perfectly OK to pass it any character pointer. The pointer doesn't have to be a string constant. Such a prototype isn't really necessary; most likely it is there to reassure you, the programmer, that the pointer you pass will still point at the same place when the function is through with it. -- _ |__ Alex Matulich (alex@bilver.UUCP) /(+__> Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817 //| \ UUCP: ...uunet!tarpit!bilver!alex ///__) bitnet: IN%"bilver!alex@uunet.uu.net"
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/07/90)
In article <1071@bilver.UUCP> alex@bilver.UUCP (Alex Matulich) writes: >As I understand it, the "const char *" means that fopen() cannot >modify the pointer in any way. Wrong -- it indicates that the function will not modify anything that can be pointed AT using that pointer. The actual pointer argument is of course passed by value and couldn't be modified by the function in any case.