Git Product home page Git Product logo

Comments (5)

manodeep avatar manodeep commented on June 30, 2024

I think both the first and second refer (mostly) to the same thing.

struct foo{
    int x;
};
typedef struct foo foo;

This lets you say

foo newvar;

instead of

struct foo newvar;

I think in the second case there is no declaring struct foo something because the struct itself was anonymous. But not totally sure; feel free to play around in godbolt

from cookies-n-code.

annehutter avatar annehutter commented on June 30, 2024

Just to clarify both methods allow this declaration
foo newvar;
However, if working with linked lists, only the first option works (which sort of makes sense as otherwise next is not defined):
typedef struct foo{ int x; foo *next; } foo;

I think I don't really understand the concept of namespace ('foo' before the brackets, to my understanding) when there is a typespace ('foo' after brackets) defined? Are there any implications if the struct is anonymous?

from cookies-n-code.

manodeep avatar manodeep commented on June 30, 2024

Ahh I see what you mean. Yes you do need a forward declaration

typedef struct foo foo;
struct foo{
    int x;
    foo *ptrtofoo;
};

I think that should work.

(Otherwise, just declare void * ptrtofoo; and then recast to struct foo * as and when necessary)

from cookies-n-code.

manodeep avatar manodeep commented on June 30, 2024

Here's the relevant StackOverflow page

Is this okay to close?

from cookies-n-code.

manodeep avatar manodeep commented on June 30, 2024

@annehutter I think this issue is resolved; I am closing for now -- please feel free to re-open.

from cookies-n-code.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.