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 6116929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:15:45+00:00 2026-05-23T15:15:45+00:00

Declaring a struct with typedef typedef struct some_struct { int someValue; } *pSomeStruct; and

  • 0

Declaring a struct with typedef

typedef struct some_struct {
int someValue;
} *pSomeStruct;

and then passing it as a parameter to some function with const declaration, implying ‘const some_struct * var’

void someFunction1( const pSomeStruct var )

turns out to become

some_struct * const var

This is also stated in Section 6.7.5.1 of the ISO C standard which states that ‘const’ in this case applies to the pointer and not to the data to which it points.

So the question is – is there a way to declare a pointer to a const struct in a shorthanded notation with typedef, or there must always be a special separate declaration for it:

typedef const struct some_struct *pcSomeStruct;
void someFunction2( pcSomeStruct var )
  • 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-23T15:15:46+00:00Added an answer on May 23, 2026 at 3:15 pm

    Basically, do not typedef pointers 🙂

    typedef struct some_struct {} some_struct;
    
    void some_function1(some_struct *var);
    void some_function2(const some_struct *var);
    void some_function3(some_struct *const var);
    void some_function4(const some_struct *const var);
    

    Or, don’t typedef at all 😀

    struct some_struct {};
    
    void some_function1(struct some_struct *var);
    void some_function2(const struct some_struct *var);
    void some_function3(struct some_struct *const var);
    void some_function4(const struct some_struct *const var);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

declaring a struct Table: struct Tables { int i; int vi[10]; Table t1; Table
In my code I'm passing around some structures by reference, declaring them mutable and
I'm declaring a struct inside my code and then trying to insert it into
What are differences between declaring a method in a base type virtual and then
I have the following types: struct X { int x; X( int val )
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct dict_pair { void *key; void *value;
In theory it seems that books sugest declaring ADT in C as: struct some_structure;
I'm having some trouble in declaring a STL Set of pointers to class instances.
constexpr int get () { return 5; } template<int N> struct Test {}; int
typedef struct tnode { ... } Treenode; Since typedef can't create a new type

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.