[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: const pains with lpcode in Lpeg 0.11
- From: Jay Carlson <nop@...>
- Date: Fri, 29 Mar 2013 17:48:33 -0400
On Mar 29, 2013, at 11:39 AM, Rob Kendrick wrote:
> On Fri, Mar 29, 2013 at 01:33:18PM +0000, Rob Kendrick wrote:
>> On Fri, Mar 29, 2013 at 01:15:12PM +0000, Gavin Wraith wrote:
>>> I am having these error messages when I try to compile
>>> lpeg 0.11:
>>>
>>> "c.lpcode", line 287: Error: assignment to 'const' object 'follow'
>>>
>>> which I guess happens because my compiler does not allow assignments to types qualified as
>>> const. Any suggestions how I get round this?
>>
>> Hmm, time for a language lawyer. At first glance, assigning to "const
>> charset follow" seems file, because charset is a typedef for an array of
>> chars. What's changing is the the pointer, not what is pointed at, and
>> that would be fine. I assume you're using Norcroft? It may be that it
>> is not expanding the typedef at the correct time.
>
> Further to this; I tried the following:
>
> typedef unsigned char byte;
> typedef byte Charset[123];
>
> void test(const Charset follow)
> {
> follow = NULL;
> }
As with many errors, this may be revealing of internal structure.
Charset has the array-nature. Giving it a name with typedef does not hide this. Consider instead this alternate declaration:
typedef unsigned char byte;
typedef struct { byte s[123]; } Charset;
gcc will indeed blow up on "follow = NULL" because now follow is a scalar, passed and returned by value.
(Remove the const and it will next tell you that assigning an int to a struct makes no sense.)
typedefs are leaky abstractions. I guess I can live with that; C++ shows in great detail what happens once you set out to make pointer-nature and scalar-nature textually transparent.