struct definition: "Undeclared..."

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
TheSamuraiElephant
Posts: 17
Joined: Thu Aug 04, 2005 9:10 pm

struct definition: "Undeclared..."

Post by TheSamuraiElephant »

I'm trying to tidy up my code by making structures for some parts but when I try to compile this (this code resides in my main function) cygwin gives me an error:

Code: Select all

//create structure for holding chunk data
		struct Chunk
		{
			unsigned short ID; //first two bytes
			unsigned int size; //last four bytes
		};

		Chunk firstChunk;

		int bytes_read = 1;
		bytes_read = sceIoRead(fdin, &firstChunk.ID, sizeof(firstChunk.ID));
here's the error cygwin gives: 'Chunk' undeclared (first use in this function)
I don't think it's recognising the struct for some reason...is it something to do with some compiler options? I've searched google but couldn't find anything.

Cheers
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: struct definition: "Undeclared..."

Post by Shine »

Try to learn some more C basics and then write "struct Chunk firstChunk".
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

You are probably more of a C++ programmer. In C++ you dont need the "struct" in front of it, but in C you do.

Heres a much better workaround that is typically found in most C code:

Code: Select all

     typdef struct _Chunk
      {
         unsigned short ID; //first two bytes
         unsigned int size; //last four bytes
      } Chunk;

      Chunk firstChunk; 
This will make typing "Chunk" just like typing: struct _Chunk. Actually, I think you can get away with taking out the _Chunk part, but I cant be sure unless I try it.

Cheers!
TheSamuraiElephant
Posts: 17
Joined: Thu Aug 04, 2005 9:10 pm

Post by TheSamuraiElephant »

thanks for the replies, it's working fine now. Actually my main problem was having to notice a variable whos name was typed out with the wrong case (should have had a capital). Stupid mistake I guess.

Thanks again :)
Post Reply