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

  • Home
  • SEARCH
  • 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 480551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:54:15+00:00 2026-05-13T00:54:15+00:00

OK, this is of no serious consequence, but it’s been bugging me for a

  • 0

OK, this is of no serious consequence, but it’s been bugging me for a
while: Is there a reason for the distinction between the -> and . operators?

Of course, the current rule is that . acts on a struct, and -> acts on
a pointer-to-struct (or union). But here’s how it works in practice.
Let s be a struct incuding an element x, and let ps be a pointer to a struct of the same form.

If you write

s->x

the compiler will spit out a warning in the way of

You meant s.x. Please retype that and recompile.

If you write

ps.x

the compiler will spit out a warning in the way of

You meant ps->x. Please retype that and recompile.

Because the compiler knows the type of both s and ps at compile time, it has all the information it needs to interpret what the correct operator would be. I suspect that this isn’t like other warnings (like a missing semicolon), in that there is no ambiguity about the correct fix.

So here’s a hypothetical proposal to the C1x standards committee (that would never be considered, because the ISO is on a conservative streak):

Given the expression lhs.rhs, if lhs is a struct or union type,
then the expression shall refer to the element of lhs named rhs.
If lhs is of type pointer-to-struct or -union, then this shall be
interpreted as (*lhs).rhs.

This would certainly save us all time, and make it easier for people to learn C [and I’ve taught enough C to say with authority that learners find the -> thing to be either confusing or annoying.]

There’s even precedent, where C does a handful of similar things. E.g., for implementation reasons, function declarations are always cast to pointer-to-function, so f(x,y) and (*f)(x,y) will both work regardless of whether f was declared as a function or a pointer to function.

So, my question: what’s wrong with this proposal? Can you think of examples where there would be fatal ambiguity between ps.x and s.x, or why keeping the mandatory distinction is otherwise useful?

  • 1 1 Answer
  • 1 View
  • 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-13T00:54:16+00:00Added an answer on May 13, 2026 at 12:54 am

    Well, if you really wanted to introduce that kind of functionality into the specification of C language, then in order to make it “blend” with the rest of the language the logical thing to do would be to extend the concept of “decay to pointer” to struct types. You yourself made an example with a function and a function pointer. The reason it works that way is because function type in C decays to pointer type in all contexts, except for sizeof and unary & operators. (The same thing happens to arrays, BTW.)

    So, in order to implement something similar to what you suggest, we could introduce the concept of “struct-to-pointer decay”, which would work in exactly the same way as all other “decays” in C (namely, array-to-pointer decay and function-to-pointer decay) work: when a struct object of type T is used in an expression, its type immediately decays to type T* – pointer to the beginning of the struct object – except when it’s an operand of sizeof or unary &. Once such a decay rule is introduced for structs, you could use -> operator to access struct elements regardless of whether you have a pointer to struct or the struct itself on the left-hand side. Operator . would become completely unnecessary in this case (unless I’m missing something), you’d always use -> and only ->.

    The above, once again, what this feature would look like, in my opinion, if it was implemented in the spirit of C language.

    But I’d say (agreeing with what Charles said) that the loss of visual distinction between the code that works with pointers to structs and the code that works with structs themselves is not exactly desirable.

    P.S. An obvious negative consequence of such a decay rule for structs would be that besides the current army of newbies selflessly believing that “arrays are just constant pointers”, we’d have an army of newbies selflessly believing that “struct objects are just constant pointers”. And Chris Torek’s array FAQ would have to be about 1.5-2x larger to cover structs as well 🙂

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

Sidebar

Related Questions

I've run into this serious error while committing, and created a bug report .
I know it's possible with jQuery, but I'm having some serious troubles with this
I have developed a game but this is a serious problem I am facing.
I have this serious: I have ASP.NET page, This page contents Update panel with
I have begun some serious reading on this framework and i am seeing where
so we're doing this assignment at Uni and i have a serious craving to
I have a serious performance problem. I have a database with (related to this
Can anyone recreate this issue? It seems to me like a quite serious bug
Ok guys, I have a serious problem with this. I have a static class
Please, give me the most serious arguments against this. Application directly opens a connection

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.