0

Why in Xcode I have error in line:

my_type a;

there must be (according to Xcode):

struct my_type a;

But in TOR code I see what they do not use struct before variable declaration.

how does it work?

2
  • 2
    Either my_type is a typedef or you're compiling with a C++ compiler. Commented Nov 14, 2020 at 20:40
  • I believe C++ will also look in the namespace for struct tags when it can't find an identifier in the "regular" namespace. C needs to be told to look there. Commented Nov 14, 2020 at 20:44

1 Answer 1

1

Okay, so structs in C. You have two options. You can do something like

struct a {
        ...
};

struct a a1;

//OR

typedef struct a {


} a;


a a1;
Sign up to request clarification or add additional context in comments.

4 Comments

Why do you name it atype instead of just a? Nothing prevents you from giving the same name.
it's very cool, I don't know that, but in tor code there is not "typedef struct ..." There is only "struct cell_t { };" but if they make variables they use "cell_t" without "struct"!
@Zyycyx How is it more understandable? If you think atype is more descriptive, then use typedef struct atype { ... } atype
@klutt Well, maybe you're right. Thank you for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.