Getting a warning when passing struct through function

lefrost

I'm trying to pass a whole structure through a function by value, and I test if the pass was successful by displaying the variables in the structure that was passed.

When I compile and run the program, the variables display correctly, but I get a warning:

warning: parameter names (without types) in function declaration

So it refers to the function prototype being declared with parameter names that had no types? But if I declared the function correctly, why am I getting this warning?

Also, in the short program I wrote to test this, the warning doesn't affect the fact that the output being displayed is correct.

But if I were to get this warning under the same circumstances (passing struct through function) when writing a larger-scale program, will it affect the output in that program being correct?

My code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void pass(Info);

typedef struct {
    char str[10];
    int num;
} Info;

void main() {
    Info i;

    strcpy(i.str, "Hello!");
    i.num = 1;

    pass(i);
}

void pass(Info i) {
    printf("%s\n", i.str);
    printf("%d\n", i.num);
}

Output:

Hello!

1

Sourav Ghosh

You have the typedef statement after the usage of the newly defined type (synonym for another type, to be nitpicky). At that point, in the function forward declaration, compiler does not know a type named Info. So, it assumes it to be a variable name.

Move the typedef before function prototype.

That said, void main() is not a valid signature for main() in a hosted environment. It should be int main(void), at least.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

struct tm becomes PST when passing through a function

From Dev

Passing malloc struct array through a function

From Dev

Passing struct pointer through a function then accessing struct data

From Dev

Warning when passing a function to a wrapped component prop

From Dev

Getting 'undefined' when passing an array through Express res.render function

From Dev

Passing a struct to a function when it takes an interface?

From Dev

Error when passing struct to function in c

From Dev

MPI segfaults when passing simple struct to function

From Dev

Getting -Wincompatible-pointer-types for struct pointer warning when compiling

From Dev

Getting [object] when passing parameter to javascript function

From Dev

passing a struct argument in a struct function

From Dev

Get warning when passing too few arguments to a javascript function

From Dev

Common Lisp - CCL, why a warning when passing a global to a local function?

From Dev

Compiler warning when passing a 2D array as function argument

From Dev

struct function passing and returning

From Dev

A weird error when passing a struct pointer to a function in C

From Dev

Passing a function out of a struct to a function

From Dev

Getting rank deficient warning when using regress function in MATLAB

From Dev

Passing through $this into function

From Dev

Passing function through useContext

From Dev

Passing parameter through function

From Dev

Memory leak when passing allocated array through recursing function

From Dev

C++ template not compiling when passing through function signature

From Dev

python list index out of range when passing an array through a function

From Dev

Getting toogleShow is not function when passing as props in react typescript functional component

From Dev

Getting unexpected lifetime issue when passing newly constructed array to function

From Dev

FileInputStream is getting closed when passing second time to a function in java

From Dev

Getting Undefined When Passing in FormData to Redux Register Function in Reactjs with NodeJS

From Dev

curl warning when passing a url

Related Related

  1. 1

    struct tm becomes PST when passing through a function

  2. 2

    Passing malloc struct array through a function

  3. 3

    Passing struct pointer through a function then accessing struct data

  4. 4

    Warning when passing a function to a wrapped component prop

  5. 5

    Getting 'undefined' when passing an array through Express res.render function

  6. 6

    Passing a struct to a function when it takes an interface?

  7. 7

    Error when passing struct to function in c

  8. 8

    MPI segfaults when passing simple struct to function

  9. 9

    Getting -Wincompatible-pointer-types for struct pointer warning when compiling

  10. 10

    Getting [object] when passing parameter to javascript function

  11. 11

    passing a struct argument in a struct function

  12. 12

    Get warning when passing too few arguments to a javascript function

  13. 13

    Common Lisp - CCL, why a warning when passing a global to a local function?

  14. 14

    Compiler warning when passing a 2D array as function argument

  15. 15

    struct function passing and returning

  16. 16

    A weird error when passing a struct pointer to a function in C

  17. 17

    Passing a function out of a struct to a function

  18. 18

    Getting rank deficient warning when using regress function in MATLAB

  19. 19

    Passing through $this into function

  20. 20

    Passing function through useContext

  21. 21

    Passing parameter through function

  22. 22

    Memory leak when passing allocated array through recursing function

  23. 23

    C++ template not compiling when passing through function signature

  24. 24

    python list index out of range when passing an array through a function

  25. 25

    Getting toogleShow is not function when passing as props in react typescript functional component

  26. 26

    Getting unexpected lifetime issue when passing newly constructed array to function

  27. 27

    FileInputStream is getting closed when passing second time to a function in java

  28. 28

    Getting Undefined When Passing in FormData to Redux Register Function in Reactjs with NodeJS

  29. 29

    curl warning when passing a url

HotTag

Archive