Re: Xcode-users Digest, Vol 10, Issue 29
Re: Xcode-users Digest, Vol 10, Issue 29
- Subject: Re: Xcode-users Digest, Vol 10, Issue 29
- From: Feliks Kluzniak <email@hidden>
- Date: Sat, 26 Jan 2013 20:38:03 +0100
Thanks for the admirable explanation. "Tis true, I misunderstood the topic of discussion: apologies for the noise.
There is, as you say, a weird inconsistency between your 2nd and 4th examples.
-- Feliks
On Jan 26, 2013, at 20:18, Aaron Montgomery <email@hidden> wrote:
> I think you are misreading the original code (as I think Chris did last night), this isn't an issue with typedef-ing a pointer. The original poster actually just typedef-ing an int:
>
> Original Poster: typedef char char_T;
> What Seems to be Your Interpretation: typedef char* char_T;
>
> The following:
>
> typedef char char_T;
>
> int f(int argc, const char* argv[])
>
> int f(int argc, const char_T* argv[])
> {
> return 0;
> }
>
> compiles without complaint, and
>
> typedef char char_T;
>
> int main(int argc, const char* argv[])
> {
> return 0;
> }
>
> also compiles without complaint, and
>
> typedef char char_T;
>
> int main(int argc, char_T* argv[])
> {
> return 0;
> }
>
> also compiles without complaint, but
>
> typedef char char_T;
>
> int main(int argc, const char_T* argv[])
> {
> return 0;
> }
>
> raises the error that argv should be of type char**.
>
> So clang seems to expect that either main is called with a second argument of const char** or main is called with a second argument of T** where T is a typedef of char, but main cannot be called with a second argument of const T** where T is a typedef of char. However, this inconsistency is not seen with functions which can be declared with prototypes using "const char**" and implemented with definitions using "const char_T**"
>
> Aaron
>
> On Jan 26, 2013, at 10:55 AM, Feliks Kluzniak <email@hidden> wrote:
>
>> This is a well-known feature of C, apparently inherited by C++. I quote from Harbison and Steele, C - A Reference Manual, FifthEdition, p. 90:
>>
>> "typedef int *int_pointer;
>> const int_pointer const_pointer;
>>
>> This makes const_pointer look like a "pointer to constant int_pointer", but it is not -- it is still a constant pointer to a (nonconstant) int."
>>
>> Then they point out that this may be rewritten as
>>
>> int_pointer const const_pointer;
>>
>> If you substitute the type definition you see
>>
>> int * const const_pointer;
>>
>> and light dawns. :-)
>>
>> Personally, I find that it helps me to avoid the confusion if I always write "const" after the type to which it refers, i.e.,
>>
>> int const * p;
>> int * const p;
>>
>> etc.
>>
>> -- Feliks
>>
>>
>> On Jan 26, 2013, at 16:47, email@hidden wrote:
>>
>>> Date: Fri, 25 Jan 2013 20:54:02 -0800
>>> From: Aaron Montgomery <email@hidden>
>>> To: Dmitry Markman <email@hidden>
>>> Cc: "email@hidden list" <email@hidden>
>>> Subject: Re: clang can not compile simple cpp file with main's second
>>> argument is typedef
>>> Message-ID: <email@hidden>
>>> Content-Type: text/plain; charset=us-ascii
>>>
>>>
>>> On Jan 25, 2013, at 7:37 PM, Dmitry Markman <email@hidden> wrote:
>>>
>>>> #include <iostream>
>>>>
>>>> typedef char char_T;
>>>>
>>>> int main(int argc, const char_T * argv[])
>>>> {
>>>> std::cout << "Hello Test World!" << std::endl;
>>>> return 0;
>>>> }
>>>
>>> If you eliminate the const, and pass a char_T** it compiles (and I think the standard char** not a const char**). What is odd to me is that it will compile if you pass a const char**, but not a const char_T**.
>>>
>>> Aaron
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Xcode-users mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden