Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:14:26+00:00 2026-05-13T18:14:26+00:00

Firstly, sample codes: Case 1: typedef char* CHARS; typedef CHARS const CPTR; // constant

  • 0

Firstly, sample codes:

Case 1:


typedef char* CHARS;
typedef CHARS const CPTR;   // constant pointer to chars

Textually replacing CHARS becomes:


typedef char* const CPTR;   // still a constant pointer to chars

Case 2:


typedef char* CHARS;
typedef const CHARS CPTR;   // constant pointer to chars

Textually replacing CHARS becomes:


typedef const char* CPTR;   // pointer to constant chars

In case 2, after textually replacing CHARS, the meaning of the typedef changed. Why is this so? How does C++ interpret this definition?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:14:27+00:00Added an answer on May 13, 2026 at 6:14 pm

    There’s no point in analyzing typedef behavior on the basis of textual replacement. Typedef-names are not macros, they are not replaced textually.

    As you noted yourself

    typedef CHARS const CPTR;
    

    is the same thing as

    typedef const CHARS CPTR;
    

    This is so for the very same reason why

    typedef const int CI;
    

    has the same meaning as

    typedef int const CI;
    

    Typedef-name don’t define new types (only aliases to existing ones), but they are “atomic” in a sense that any qualifiers (like const) apply at the very top level, i.e. they apply to the entire type hidden behind the typedef-name. Once you defined a typedef-name, you can’t “inject” a qualifier into it so that it would modify any deeper levels of the type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I studied apple's sample codes : SeismicXML and TopSongs but both of them
Firstly to show you what I am trying to achieve in the view, a
Firstly, I wrote my customized setter for an NSString* like this: - (void)setDateString:(NSString *)newDateString
Firstly, is it safe to mix green threads such as eventlet or gevent with
Firstly, is there a command for getting help and parameters for each sos command
Firstly, I'm quite a newbie in rails/heroku, so forgive the newbiness in advance! I
Firstly some background,.. IVe started a new job as PHP developer with a company
Firstly, the bash script works fine when I call it outside of ant. Here
Firstly sorry if this is a common question but I couldn't find anything on
Firstly, I know this [type of] question is frequently asked, so let me preface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.