473,396 Members | 1,843 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,396 software developers and data experts.

mystified by compiler error

131 128KB
I've got a project with five C source files, one CPP source file and a single header such as

Expand|Select|Wrap|Line Numbers
  1. #ifndef __MYHEADER__
  2.  
  3. // basic includes
  4. // several defines
  5. // a few globals
  6.  
  7. typedef struct
  8. {
  9.    // data
  10. } foo_1;
  11.  
  12. #if __cplusplus
  13.  extern "C" {
  14. #endif
  15.  
  16. // number of function prototypes for cpp source file
  17.  
  18. #if __cplusplus
  19. }
  20. #endif
  21.  
  22. // function prototypes for c source files
  23.  
  24. #endif
  25.  
all source files include this header

Everything above compiles without errors or warnings. When I modify the above header to include another structure and a function prototype, I get compiler errors that strangely can be corrected using the "struct" keyword in the prototype and definition.

Expand|Select|Wrap|Line Numbers
  1. // modified header
  2.  
  3. typedef struct
  4. {
  5.    // data
  6. } foo_1;
  7.  
  8. typedef struct
  9. {
  10.     // data
  11. } foo_2;
  12.  
  13. // new prototype
  14.  
  15. void foo_bar(foo_2 *);
  16.  
In C source file

Expand|Select|Wrap|Line Numbers
  1. void foo_bar(foo_2 *bar)
  2. {
  3.    // function def
  4. }
  5.  
error C2143: syntax error : missing ')' before '*'
error C2143: syntax error : missing '{' before '*'
error C2059: syntax error : ')'
error C2059: syntax error : ';'

If I change the function to below, the errors mysteriously go away.

Expand|Select|Wrap|Line Numbers
  1. void foo_bar(struct foo_2 *);
  2. void foo_bar(struct foo_2 *bar)
  3. {
  4.   //
  5. }
If I typedef the struct, why is seemingly losing the type? I've never had an issue like this before; what is the cause of this?

TIA
Jul 7 '13 #1
2 1077
weaknessforcats
9,208 Expert Mod 8TB
In C you must code struct foo_2*.

In C++ you can just code foo_2*.

C++ is not C. Doesn't work like C and some C won't compile as C++.

BTW this code:

#ifndef __MYHEADER__

should have a #define __MYHEADER__ as the next line.
Jul 7 '13 #2
divideby0
131 128KB
thanks wfc.

I figured out what the problem was; the IDE set the path of the C source file to an older project folder, which didn't have the structures defined in the samely named header file of the older project. I updated the path, and it worked as expected.

Thank you for taking the time to look; I do appreciate it.
Jul 7 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: paul calvert | last post by:
I hope somewhere here has encountered and solved a similar problem in the past. 1) on a new Win2000 PC: installed Visual C++ 6.0 download & install single file Service Pack 5.0 2) try to...
30
by: Neil Zanella | last post by:
Hello, Allow me to share my frustrations with GNU g++. This is the second time something similar happens to me: I can't find anything wrong with my C++ program and yet I get segfaults, and...
19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
6
by: David Lack | last post by:
Hi, I recently installed a 60-day trial of .NET 2003 on my development system. I made tests with previous personal projects (which compiled ok with VC6) and some open source files, and keep...
10
by: PufferFish | last post by:
Hi folks, I hope that this is the correct group for these things, apologies if not. I've got a strange compiler error. It appears to be similar to the issue described in knowledgebase...
5
by: dilip ranganathan | last post by:
Hi I have taken the liberty to cross-post this. It appeared on c.l.c++.m but the ICE is regarding VS.NET 7.1 C++ compiler. post follows: ==============================================...
3
by: Robert | last post by:
Every time I navigate to any .aspx file on my computer, I get the error below. According to MSDN this indicates that my CLR is corrupt, but I've re-installed the .NET framework with no help. Also...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
1
by: kvarada | last post by:
Hello Experts, I am building my application on WinNT.4.0_i386_MSVC.7.1 platform. When I build the application on a stand alone machine, it builds fine. But when I build the same application from a...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.