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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:31:34+00:00 2026-05-10T15:31:34+00:00

This came up from this answer to a previous question of mine . Is

  • 0

This came up from this answer to a previous question of mine. Is it guaranteed for the compiler to treat array[4][4] the same as array[16]?

For instance, would either of the below calls to api_func() be safe?

void api_func(const double matrix[4][4]);  // ...  {   typedef double Matrix[4][4];    double* array1 = new double[16];   double array2[16];    // ...    api_func(reinterpret_cast<Matrix&>(array1));   api_func(reinterpret_cast<Matrix&>(array2)); } 
  • 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. 2026-05-10T15:31:35+00:00Added an answer on May 10, 2026 at 3:31 pm

    From the C++ standard, referring to the sizeof operator:

    When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element.

    From this, I’d say that double[4][4] and double[16] would have to have the same underlying representation.

    I.e., given

    sizeof(double[4]) = 4*sizeof(double) 

    and

    sizeof(double[4][4]) = 4*sizeof(double[4]) 

    then we have

    sizeof(double[4][4]) = 4*4*sizeof(double) = 16*sizeof(double) = sizeof(double[16]) 

    I think a standards-compliant compiler would have to implement these the same, and I think that this isn’t something that a compiler would accidentally break. The standard way of implementing multi-dimensional arrays works as expected. Breaking the standard would require extra work, for likely no benefit.

    The C++ standard also states that an array consists of contiguously-allocated elements, which eliminates the possibility of doing anything strange using pointers and padding.

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

Sidebar

Related Questions

let me tell you a bit about where this question came from. I have
After some stupid musings about Klingon languages, that came from this post I began
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
This came up in Hidden features of Python , but I can't see good
This came up in a conversation I was having online, and it occured to
This issue came up when I got different records counts for what I thought
I came across this article written by Andrei Alexandrescu and Petru Marginean many years
I came across this recently, up until now I have been happily overriding the
I came across this class while reading a C# book and have some questions.
This is beyond both making sense and my control. That being said here is

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.