473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

typedef struct { ... } S1

Wei
Hi there!

I have a very wired problem when I develop a C/C++ based application using
Visual Studio 2005.

#include <stdio.h>

typedef struct _S1 {
int data;
int text;
} S1;
int main()
{
printf("Hello, Vorbis!\n");
S1 oy;
}

Code above doen't compile. On line 12 it states error C2275: 'S1': illegal
use of this type as an expression.

This code compiles well in gcc. So I wonder if I have wrong setting
somewhere in Visual Studio.

Hope somebody can give me a hint.
Apr 18 '06 #1
5 1334
Wei
Aha, it has been a while since I coded C last time. I have been spoiled by
C#, java.

In C declartion must be made in the beginning of the block. It works fine now.

/Wei
Apr 18 '06 #2
Wei wrote:
Aha, it has been a while since I coded C last time. I have been spoiled by
C#, java.

In C declartion must be made in the beginning of the block. It works fine now.

/Wei


Wei:

Unless you have a special reason to use C, I suggest you compile your
program as C++. The you can put declarations where you like. Just change
your file extension to .cpp or .cxx rather than .c. It is also possible
to change the compile setting for the .c files in your project, so that
they are compiled as C++ (but I think you have to do each file separately).

David Wilkinson
Apr 18 '06 #3
In additionally, this C/C++ compiler option can be specified in Project
Setting dialog->C/C++->Advanced->"Compile As".

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 19 '06 #4
Jeffrey Tan[MSFT] wrote:
In additionally, this C/C++ compiler option can be specified in Project
Setting dialog->C/C++->Advanced->"Compile As".


Jeffrey:

In my experience (in 2003.NET) this does not work, at least in my
situation. I had an existing C++ project, to which I wanted to add a
bunch. of .c files, and compile them as C++. I was not the owner of
these files, so I did not want to change the extension (which I would
probably have done otherwise). The setting you mention was already set
to C++, but the added files compiled as C, and it seemed I had to change
each one. In the new VStudio IDE this is very painful because you have
to open the Properties dialog separately for each file.

David Wilkinson
Apr 19 '06 #5
Hi David,

However, in my VS.net2003 project, if I added a test.c file in the project,
then add the following code to the file:

#include <stdio.h>

typedef struct _S1 {
int data;
int text;
} S1;
int test1()
{
printf("Hello, Vorbis!\n");
S1 oy;
return 1;
}

With that compiler option set to C++, it will compile without any problem.
It will only generate error when setting the compiler to C style.

Can you please give it a re-check? Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
8
by: J Krugman | last post by:
My compiler complains if I do something like this typedef struct { node *next; } node; but it's OK with typedef struct superfluous_identifier { superfluous_identifier *next;
15
by: Merrill & Michele | last post by:
typedef struct { WORD versionNumber; WORD offset; } MENUITEMTEMPLATEHEADER; This is from vol 5 of unnamed platform's programmer's reference. I could make this conforming by enclosing...
2
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the...
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
8
by: Ronny Mandal | last post by:
Consider these two: Typedef struct { int foo, bar } FooBar; struct FooBar { int foo, bar }; What woul be the only difference here; just that I can create new instances by 'Foobar fb, *pfb',...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
8
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.