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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:31:18+00:00 2026-05-29T11:31:18+00:00

C language ensures that a pointer to any struct may be converted to void

  • 0

C language ensures that a pointer to any struct may be converted to void * and vice versa. Also, the language permits to define pointers to a struct also if it’s undefined. I would assume that, since the compiler doesn’t know anything about these structures, their pointers should have the same physical representation. Let’s consider these lines into two separate modules:

/* FILE1.c */
void *mem = ...; //Points to a suitable memory block
struct s1 *p1; //No implementation given for struct s1
void *mem2;

p1 = (struct s1 *)mem;
mem2 = &p1;


/* FILE2.c */
extern void *mem2;
struct s2 { /*...fields...*/ };
struct s2 *p2;

p2 = *(struct s2 **)mem2;

Is this code able to work on all the platforms, provided that the memory block is large enough to contain struct s2 (e.g. allocated by malloc(sizeof(struct s2)))?

In other words, is it correct (i.e. portable) to reinterpret a memory cell containing a pointer to struct s1 structure as if it were a pointer to struct s2?

(Disclaimer: I am perfectly aware that this is a very weird way to play with pointers, my question is theoretical)

  • 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-29T11:31:18+00:00Added an answer on May 29, 2026 at 11:31 am

    In C, pointers are not required to have the same size or representation.

    It means sizeof (int *) can be different to sizeof (double *) for example.

    The only requirements are:

    • void * , char *, signed char * and unsigned char * have the
      same representation.

    • Pointers to structures have the same representation.

    • Pointers to unions have the same representation.

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

Sidebar

Related Questions

Language Integrated Query. Now I know that the acronyms are. I have seen C#
For the downvote fairies.. I know that php is the wrong language for this...
I am aware that the specification of the C language does not dictate the
I want to make a multi-language site, such that all or almost all pages
In my game (that is also written in C#) I want to include some
I'm writing a program in gcc that has asm language for performance-critical sections, and
Language used: C# Theory: I want to create a file with the flag FileOptions.DeleteOnClose
Language: asp This is sample of my code: str = www.example.com/gotobuy.aspx?id=1234 key_word = .obuy.
Language = C# .NET version = 3.5 When my code performs syntax highlighting the
Language Visual Basic 6. I want to know if there is an open source

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.