Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2006

Tip: Looking for answers? Try searching our database.

typedef struct { ... } S1

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wei - 18 Apr 2006 10:32 GMT
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.
Wei - 18 Apr 2006 11:17 GMT
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
David Wilkinson - 18 Apr 2006 11:27 GMT
> 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
"Jeffrey Tan[MSFT]" - 19 Apr 2006 03:40 GMT
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.
David Wilkinson - 19 Apr 2006 11:26 GMT
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
"Jeffrey Tan[MSFT]" - 20 Apr 2006 03:14 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.