H
H
HelpMePlease22020-11-27 18:48:39
C++ / C#
HelpMePlease2, 2020-11-27 18:48:39

Code not compiling?

An error occurs while compiling this code.

#include <stdio.h>

struct {
        int debug;
} config;
config.debug=1;

int main() {
        printf("%d",config.debug);
        return 0;
}


The error is like this
ain.c:6:1: error: unknown type name 'config'
config.debug=1;
^
main.c:6:7: error: expected identifier or '('
config.debug=1;
      ^
2 errors generated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-11-27
@HelpMePlease2

Your assignment operation lies outside the function. The compiler waits there for declarations of variables, functions, types, that's all, and you have an operation there. Move the assignment to main().
If you want to initialize a structure, you can use an initialization list:

struct {
        int debug;
} config = {1};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question