Re: Expected behavior for -cs and -ncs
Ian Carvalho <[email protected]>
| Newsgroups | gmane.comp.gnu.indent.bugs |
|---|---|
| Message-ID | <[email protected]> |
david ingamells wrote:
> John E Hein wrote:
>> david ingamells wrote at 19:42 +0200 on Jul 23, 2008:
>> > This works in 2.2.10:
>> > > $ indent -npro -ncs
>> > > unsigned char *cp = (unsigned char *)ptr;
>> > int
>> > foo ()
>> > {
>> > return (int)n;
>> > }
>> > > $ indent -npro -cs
>> > > unsigned char *cp = (unsigned char *) ptr;
>> > int
>> > foo ()
>> > {
>> > return (int) n;
>> > }
>> > > > I know of no update that fixed this in 2.2.10, so I am
>> surprised that it > doesn't work in 2.2.9.
>> > I have added this to the regression test now, so it will be
>> checked in > the future.
>>
>> Seems okay in my local test here on 2.2.9, too...
>>
>>
>> echo '(unsigned char *)ptr;' | gindent -npro -cs
>> (unsigned char *) ptr;
>>
>> echo '(unsigned char *)ptr;' | gindent -npro -ncs
>> (unsigned char *)ptr;
>>
>> However, --no-space-after-cast fails:
>>
>>
>> echo '(unsigned char *)ptr;' | gindent -npro --space-after-cast
>> (unsigned char *) ptr;
>>
>> echo '(unsigned char *)ptr;' | gindent -npro --no-space-after-cast
>> indent: unknown option "no-space-after-cast"
>>
>>
>>
> A quick check in the code explains why:
>
> {"no-space-after-casts", "ncs"},
>
> And the manual says the same. I think what is best is that I update
> the manual to remove the trailing "s" and recognise both forms in the
> code.
> That way users will move over to the right one and existing users
> won't get a nasty surprise.
>
On seeing your responses, went through the code I am trying to indent.
Looks like the example I have given is flawed.
When the cast happens with a typedef'd variable then it does not seem to
work.
Using this:
--- start ---
typedef unsigned char uchar;
unsigned char *cp = (unsigned char *)ptr;
uchar *ucp = (uchar *)ptr;
--- end --
as the source
$ indent -npro -ncs
I get
--- start ---
typedef unsigned char uchar;
unsigned char *cp = (unsigned char *)ptr;
uchar *ucp = (uchar *) ptr;
--- end ---
and for
$ indent -npro -cs
I get
--- start ---
typedef unsigned char uchar;
unsigned char *cp = (unsigned char *) ptr;
uchar *ucp = (uchar *) ptr;
--- end ---
Thus, the space is present in both cases if the cast is to a typedef'd type.
Is this the expected behavior?
Thanks