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

The Archive Base Latest Questions

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

I have a few reasons to define a type for a fixed length array

  • 0

I have a few reasons to define a type for a fixed length array such as this:

typedef float fixed_array_t[NX][NY];

I then want to pass references to fixed_array_t instances around to other functions. I’m getting a compiler warning from both GCC and CLANG though I’m seeing correct behavior.

What is this compiler warning telling me and how should my code be modified to avoid the warning? Bonus, why do I have to #define the array size? Compile-time constants apparently don’t work. error: variably modified ‘fixed_array_t’ at file scope

Here is a small demonstration code:

#include <stdio.h>
#define NX 2  // also, why does const int NX = 2; not work?
#define NY 3
typedef float fixed_array_t[NX][NY];

void array_printer( const fixed_array_t arr )
{
    int i, j;
    for (i = 0; i < NX; i++ )
        for( j=0; j < NY; j++ )
            printf("Element [%d,%d]=%f\n", i,j, arr[i][j] );
}

int main( int argc, char ** argv )
{
    fixed_array_t testArray = { {1,2,3}, {4,5,6} };
    array_printer( testArray );
}

GCC warning:

warning: passing argument 1 of ‘array_printer’ from incompatible pointer type

CLANG warning (actually compiling equivalent code in OpenCL):

warning: incompatible pointer types passing 'fixed_array_t' (aka 'real [2][3]'), expected 'real const (*)[3]'

Yet program operation is fine:

Element [0,0]=1.000000
Element [0,1]=2.000000
Element [0,2]=3.000000
Element [1,0]=4.000000
Element [1,1]=5.000000
Element [1,2]=6.000000
  • 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-26T18:33:00+00:00Added an answer on May 26, 2026 at 6:33 pm

    If you just want the problem solved, you can use a struct to encapsulate your array:

    $ cat struct.c ; make CFLAGS=-Wall -Wextra struct ; ./struct
    #include <stdio.h>
    
    #define NX 2
    #define NY 3
    
    typedef struct fixed {
        float arr[NX][NY];
    } fixed_t;
    
    void array_printer( const fixed_t f)
    {
        int i, j;
        for (i = 0; i < NX; i++ )
            for( j=0; j < NY; j++ )
                printf("Element [%d,%d]=%f\n", i,j, f.arr[i][j] );
    }
    
    
    int main(int argc, char *argv[]) {
        fixed_t f = {.arr={ {1,2,3}, {4,5,6} }};
        array_printer(f);
        return 0;
    }
    
    cc -Wall    struct.c   -o struct
    Element [0,0]=1.000000
    Element [0,1]=2.000000
    Element [0,2]=3.000000
    Element [1,0]=4.000000
    Element [1,1]=5.000000
    Element [1,2]=6.000000
    

    No warnings, no errors, and only slightly more annoying to use (f.arr[][] rather than arr[][] in the array_printer, for example).

    If you amend the struct fixed to include the NX and NY dimensions, you could even have multiple different-sized objects in your program. (Though you’d slightly lose the benefits of compile-time-known bounds, I’m not sure how much that really buys you.)

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

Sidebar

Related Questions

I have few question in this regard When you create an internet page, does
I have few nested DIVs at page. I want to add event only for
I know this question could have passed a few times here but I haven't
I want to have more control over macros such as assertions (and some logging
So I have run up against this problem a few times: I have some
I have few asynchronous tasks running and I need to wait until at least
I have few different applications among which I'd like to share a C# enum.
We have few components like libraries dlls When initially created I ran the following
I have few small basic problems : How to format : int i =
I have few Question for which I am not able to get a proper

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.