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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:19:29+00:00 2026-06-01T21:19:29+00:00

I have declared a struct , and I try to pass an array of

  • 0

I have declared a struct, and I try to pass an array of those structs (as well as a double array of doubles, and an integer) into a function. I get an "array type has incomplete element type" message from gcc when I compile it. What have I gotten wrong in how I pass the struct to the function?

typedef struct graph_node {
  int X;
  int Y;
  int active;
} g_node;

void print_graph(g_node graph_node[], double weight[][], int nodes);

I have also tried struct g_node graph_node[], but I get the same thing.

  • 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-06-01T21:19:30+00:00Added an answer on June 1, 2026 at 9:19 pm

    It’s the array that’s causing trouble in:

    void print_graph(g_node graph_node[], double weight[][], int nodes);
    

    The second and subsequent dimensions must be given:

    void print_graph(g_node graph_node[], double weight[][32], int nodes);
    

    Or you can just give a pointer to pointer:

    void print_graph(g_node graph_node[], double **weight, int nodes);
    

    However, although they look similar, those are very different internally.

    If you’re using C99, you can use variably-qualified arrays. Quoting an example from the C99 standard (section §6.7.5.2 Array Declarators):

    void fvla(int m, int C[m][m]); // valid: VLA with prototype scope
    
    void fvla(int m, int C[m][m])  // valid: adjusted to auto pointer to VLA
    {
        typedef int VLA[m][m];     // valid: block scope typedef VLA
        struct tag {
            int (*y)[n];           // invalid: y not ordinary identifier
            int z[n];              // invalid: z not ordinary identifier
        };
        int D[m];                  // valid: auto VLA
        static int E[m];           // invalid: static block scope VLA
        extern int F[m];           // invalid: F has linkage and is VLA
        int (*s)[m];               // valid: auto pointer to VLA
        extern int (*r)[m];        // invalid: r has linkage and points to VLA
        static int (*q)[m] = &B;   // valid: q is a static block pointer to VLA
    }
    

    Question in comments

    […] In my main(), the variable I am trying to pass into the function is a double array[][], so how would I pass that into the function? Passing array[0][0] into it gives me incompatible argument type, as does &array and &array[0][0].

    In your main(), the variable should be:

    double array[10][20];
    

    or something faintly similar; maybe

    double array[][20] = { { 1.0, 0.0, ... }, ... };
    

    You should be able to pass that with code like this:

    typedef struct graph_node
    {
        int X;
        int Y;
        int active;
    } g_node;
    
    void print_graph(g_node graph_node[], double weight[][20], int nodes);
    
    int main(void)
    {
        g_node g[10];
        double array[10][20];
        int n = 10;
    
        print_graph(g, array, n);
        return 0;
    }
    

    That compiles (to object code) cleanly with GCC 4.2 (i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)) and also with GCC 4.7.0 on Mac OS X 10.7.3 using the command line:

    /usr/bin/gcc -O3 -g -std=c99 -Wall -Wextra -c zzz.c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have const struct aiScene *scene; declared in class. In the function where I
I have declared the following struct: typedef struct _RECOGNITIONRESULT { int begin_time_ms, end_time_ms; char*
I'm trying to implement tree algorithms in C. I have declared a extern struct
I have declared an array in the form: var refs = { 'EE810': Presence
I have declared an external function with a GCC weak attribute in a .c
Ok... I have this struct and comparison function- struct Edge { char point1; char
I have a DLL with one single function That gets five doubles and one
I have declared an associative array and now want to print it: #include <map>
I have a struct called Ambigous, and inside the struct I have an array
In my data.h file I have: typedef struct { double ***grid; } Solver; In

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.