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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:27:02+00:00 2026-06-08T00:27:02+00:00

I am trying to compile the following simple code in Workbench: 1. typedef float

  • 0

I am trying to compile the following simple code in Workbench:

 1. typedef float matrixType[3][3]
 2.     
 3. void my_func(matrixType matrix)
 4. {
 5.     printf("matrix[0][0] = %g\n",matrix[0][0]);
 6. }
 7. 
 8. void main()
 9. {
10.     matrixType my_matrix = {{0,1,2},{3,4,5},{6,7,8}};
11.     matrixType* ptr_matrix = &my_matrix;
12. 
13.     my_func(*ptr_matrix);
14. }

I receive the following warning:

test.c:13: warning: passing arg 1 of `my_func' from incompatible pointer type

I can’t understand, what am I doing wrong. The compilation of the same code in Visual Studio works without any warnings, but in Workbench something is going wrong.

Thanks.

  • 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-08T00:27:04+00:00Added an answer on June 8, 2026 at 12:27 am

    With gcc (GCC) 4.5.3 with all warnings turned on it also compiles fine after making the following changes:

    1. Add a semicolon after the first line.
    2. Add #include <stdio.h> at top.
    3. Change the return type of main to int.
    4. Add return 0; as the last line.

    The void main() is not correct C even though it appears in various books, manuals, and web tutorials. On some architectures it will cause strange problems, usually as the program terminates.

    Taking the address of an array type is challenging the workbench type checker. I’m not going to drag out the C standard to figure out if the workbench warning is correct. It’s probably a bug.

    But I’m pretty sure that if you recode this way you will see no errors with any compiler:

    #include <stdio.h>
    
    typedef float rowType[3];
    typedef rowType matrixType[3];
    
    void my_func(matrixType matrix) 
    { 
       printf("matrix[0][0] = %g\n",matrix[0][0]); 
    } 
    
    int main() 
    { 
        matrixType my_matrix = {{0,1,2},{3,4,5},{6,7,8}}; 
        rowType* ptr_matrix = my_matrix; 
        my_func(ptr_matrix);
        return 0; 
    } 
    

    The reason is that my_matrix is automatically converted to a pointer to it’s first element in the assignment

    rowType* ptr_matrix = my_matrix; 
    

    This is just as in

    char s[] = "hello world!"; 
    char *p = s;
    

    the array name s is converted to a pointer to its first element.

    The parameter in void my_func(matrixType matrix) has a type identical to rowType* because all arrays are also passed as pointers to first elements. So all the types in this code must match in a way that’s very clearly defined in the C standard. &my_matrix may not be incorrect, but it’s an “edge case” more likely to expose type checking bugs.

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

Sidebar

Related Questions

I am trying to compile the following very very simple piece of source code:
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
When trying to compile the following code, I am getting a warning that line
I am trying to compile the following code and i am getting the error:
I'm trying to compile the following program: #include<functional> #include<iostream> int main(int argc, char* argv[],
I am trying to compile my gcc code using the following make command .
I'm trying to compile some code which contains the following declaration, because I would
Let's look at the simple Java code in the following snippet: public class Main
I'm trying to compile the following sample code available at XERCES site: #include <xercesc/util/PlatformUtils.hpp>
I'm trying to compile simple example to use the boost concept_check Code is as

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.