Skip to main content

error: invalid application of ‘sizeof’ to incomplete type ‘struct ’

list.c:47:39: error: invalid application of ‘sizeof’ to incomplete type ‘struct Litsnode’

So, I was trying to run a program based on linked list and this is what I got.
This is a very silly problem. I am mentioning it here just to help those who got frustrated like me :-\


Let me show you the line where this error occurred :

46  struct Listnode * newnode;
47  newnode = (struct Listnode *) malloc(sizeof(struct Litsnode));

Now, View it properly. Check the name(spelling) of the structure mentioned to sizeof : "struct Litsnode". Though the defined name of the structure was : "struct Listnode"

That's it. 
This happens all the time that we may type something wrong. The important thing is to identify it. :-)

Feel free to give any suggestions :)

Comments

  1. Was sitting all evening trying to understand what is wrong with my program and all it was I mistyped "Connection"- forgot second n.
    Than you for paying my attention Gene or else I think I would never ever found it. ;)
    -Ed

    ReplyDelete
  2. i have also done the same mistake and it makes me laugh that i was getting frustrated over a silly mistake thank you for sharing the useful info.

    ReplyDelete

Post a Comment

Popular posts from this blog

Expandable Arrays in C : behind the code

Arrays. They are beautiful. In C, we always try to work through restrictions arrays have i.e the size of the array must be statically defined. We always want a dynamic array whose size can be decided at run-time. There are ways which we use widely for e.g by using pointers and then dynamically allocating memory to it using malloc or calloc. But depending on the situation, we might require more efficient and organizable ways. I will explain the concept with a series of examples as in how simple arrays evolved to the tricky expandable ones. The classic way is to use pointers This snippet will allocate a memory block of size = array_size(integer array). Though this is not what I wanted to explain because this way is too clumsy. Imagine if you need 10 dynamic arrays in your program, you have to write these four lines each time and you have to keep track of all the 10 sizes. A better way is to use structures: We can simply create a structure containing two elements: array_size and...

ssh: Could not resolve hostname git: No address associated with hostname

I came across this error when I needed to clone a git repo. I tried few times but I couldn't get it working. There were few suggestions on the internet, but none resolved my issue. So, lets get to the point, this issue may occur due to following reasons: 1. If you are using proxy to access git and it is not properly configured/proxy is not allowing you access git due to permission issues. More here: git-clone-no-address-associated-with-name getting-git-to-work-with-a-proxy-server 2. This happens due to a silly mistake. [I do make silly mistakes sometimes] Are you actually using git clone for cloning? I used this - ssh git@github.com:neovim/neovim.git instead of git clone git@github.com:neovim/neovim.git ----- Hope this have resolved your issue :-) Happy Coding.