#include <stdio.h>
typedef struct point{
int x;
int y;
};
void main (void){
struct point pt;
pt.x = 20;
pt.y = 333;
struct point pt2;
pt2.y = 55;
printf("asd");
return;
}
VS 2008
c:\documents and settings\lyd\mis documentos\ejercicio1.c\ejercicio1.c\ejercicio1.c(14) : error C2143: syntax error : missing ';' before 'type'
c:\documents and settings\lyd\mis documentos\ejercicio1.c\ejercicio1.c\ejercicio1.c(15) : error C2065: 'pt2' : undeclared identifier
c:\documents and settings\lyd\mis documentos\ejercicio1.c\ejercicio1.c\ejercicio1.c(15) : error C2224: left of '.y' must have struct/union type
Build log was saved at "file://c:\Documents and Settings\LYD\Mis documentos\ejercicio1.c\ejercicio1.c\Debug\BuildLog.htm"
ejercicio1.c - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Since the question is tagged C (and not C++), and since the compiler is MSVC 2008, you are stuck with C89 semantics. That means you cannot declare variables in a block after the first statement. Hence, the second struct variable is not allowed there. (Both C99 and C++ allow you declare variables at any point in the block. Go tell MS to update their C compiler to support C99.)
Your other bug is that
main()returns anint, hence:Some hours later: the keyword typedef is not needed in the code because no name is specified after the close brace and before the semi-colon. This doesn’t stop it compiling; it will elicit a warning with the compiler set fussy.