Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Nov 2001 00:00:33 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Matthew Blacklow <matthew.blacklow@ticca.com>
Cc:        questions@FreeBSD.ORG
Subject:   Re: Changing the value of a constant
Message-ID:  <20011107060033.GA67329@dan.emsphone.com>
In-Reply-To: <NFBBICMIIEMNIMGOBPCMMEAPCHAA.matthew.blacklow@ticca.com>
References:  <NFBBICMIIEMNIMGOBPCMMEAPCHAA.matthew.blacklow@ticca.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Nov 07), Matthew Blacklow said:
> I am writing a C program under FreeBSD and am required to open a file
> for reading. I have no trouble opening files when the address is hard
> coded. However the fopen function requires that the path be a const
> char. My problem is that the everytime the program runs it need to
> open a different file and that is determined sometime during the
> programs execution. I need to know how to modify the value of a
> constant under C.

The 'const' attribute in function prototypes refers to the function's
behaviour: it promises not to modify the data you pass to it.  For
example, take a look at the prototype to strcpy:

char *strcpy(char *dst, const char *src);

It promises not to modify the string pointed to by src, but does not
promise that dst will be the same value it was before it was called (it
would not be a very good strcpy routine if it was :)

Your code is free to modify its own string pointers between calls to
fopen().

-- 
	Dan Nelson
	dnelson@allantgroup.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011107060033.GA67329>