Click here to Skip to main content
15,557,706 members
Articles / Programming Languages / C++
Tip/Trick
Posted 11 Nov 2016

Tagged as

Stats

8.9K views
5 bookmarked

Solving a C4183 Conundrum

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
11 Nov 2016CPOL1 min read
This tip describes how I resolved a C4183 compiler error emitted by the Visual C++ 2013 compiler.

Introduction

In the course of implementing a class in a Visual C++ project, I encountered an error (documented as a warning) that I couldn't resolve by any of the methods discussed elsewhere. Thankfully, the solution that I developed, though slightly novel, is quite straightforward; move the typedef directly into the class definition header.

Background

Having worked more in straight C than C++, and implemented C interfaces for most of my custom APIs, I was accustomed to declaring a structure and a pointer to one of its kind as follows.

C++
typedef struct _PVT_SAFER_MUTEX
{
    HANDLE    ThisMutex ;
    DWORD    OwnerThread ;
} PVT_SAFER_MUTEX , * LPPVT_SAFER_MUTEX ;

It was a matter of habit to define structures and pointers to structures in this way in a header, include that header within another header, then declare functions that return the pointer type.

C++
LPPVT_SAFER_MUTEX MyFunction ( SAFEER_MUTEX_HANDLE pHandle ) ;

This works like a champ in straight C code.

Now comes a need to do something similar in the header that declares a class.

C++
LPPVT_SAFER_MUTEX CHandleManager::GetMutexInfo ( SAFEER_MUTEX_HANDLE pHandle ) ;

Try this with the structure typedef in a separate header, and you get Compiler Warning (level 1) C4183, 'identifier': missing return type; assumed to be a member function returning 'int'.

Points of Interest

After about an hour of studying numerous articles about compiler warnning/error C4183, I decided to move the typedef from the external header into the header that declares the C++ class that contains methods that return pointers to the structure.

This worked.

On reflection, putting the typedef in the header that defines the class that uses it is a cleaner design, because it makes the class declaration more self-contained.

History

Friday, 11 November 2016 is the initial publication of this tip.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I deliver robust, clean, adaptable, future-ready applications that are properly documented for users and maintainers. I have deep knowledge in multiple technologies and broad familiarity with computer and software technologies of yesterday, today, and tomorrow.

While it isn't perceived as sexy, my focus has always been the back end of the application stack, where data arrives from a multitude of sources, and is converted into reports that express my interpretation of The Fundamental Principle of Tabular Reporting, and are the most visible aspect of the system to senior executives who approve the projects and sign the checks.

While I can design a front end, I prefer to work at the back end, getting data into the system from outside sources, such as other computers, electronic sensors, and so forth, and getting it out of the system, as reports to IDENTIFY and SOLVE problems.

When presented with a problem, I focus on identifying and solving the root problem for the long term.

Specialties: Design: Relational data base design, focusing on reporting; organization and presentation of large document collections such as MSDS libraries

Development: Powerful, imaginative utility programs and scripts for automated systems management and maintenance

Industries: Property management, Employee Health and Safety, Services

Languages: C#, C++, C, Python, VBA, Visual Basic, Perl, WinBatch, SQL, XML, HTML, Javascript

Outside Interests: Great music (mostly, but by no means limited to, classical), viewing and photographing sunsets and clouds, traveling by car on small country roads, attending museum exhibits (fine art, history, science, technology), long walks, especially where there is little or no motor traffic, reading, especially nonfiction and thoughtfully written, thought provoking science fiction

Comments and Discussions

 
QuestionDifference between C and C++ Pin
Joe Pizzi14-Nov-16 14:58
Joe Pizzi14-Nov-16 14:58 
AnswerRe: Difference between C and C++ Pin
David A. Gray1-Dec-16 21:11
David A. Gray1-Dec-16 21:11 
AnswerRe: Difference between C and C++ Pin
TheGreatAndPowerfulOz9-Dec-16 13:16
TheGreatAndPowerfulOz9-Dec-16 13:16 
SuggestionCode example.. Pin
PhilipOakley14-Nov-16 7:43
professionalPhilipOakley14-Nov-16 7:43 
GeneralRe: Code example.. Pin
David A. Gray1-Dec-16 21:06
David A. Gray1-Dec-16 21:06 
SuggestionRe: Code example.. Pin
PhilipOakley2-Dec-16 13:10
professionalPhilipOakley2-Dec-16 13:10 
Hi David,

The point was to add in a fourth sample that showed the result of the change, especially as it took an hour to find the issue. Though mainly it's that some folks are poor at learning from reading prose and much prefer visual learning (i.e. seeing the structure).

In my case I'd decided to read your article because it's title looked interesting, rather than being a C++ coder, so seeing the working example would ensure everyone 'get's it'.

C++
typedef struct _PVT_SAFER_MUTEX /* sample 1 */


C++
LPPVT_SAFER_MUTEX MyFunction ( SAFER_MUTEX_HANDLE pHandle ) ; /* sample 2 OK in C */


Oops was it a spelling there SAFEER_MUTEX_HANDLE ?

C++
LPPVT_SAFER_MUTEX CHandleManager::GetMutexInfo ( SAFEER_MUTEX_HANDLE pHandle ) ; /* sample 3 Not OK C4183 */


So then insert the solution with the typedef header inserted..

C++
LPPVT_SAFER_MUTEX CHandleManager::GetMutexInfo ( struct Whatever Here SAFEER_MUTEX_HANDLE pHandle ) ; /* sample 4 Fixed ?? */


As you see I hadn't quite understood what the change should be (my ignorance). Hopefully adding the refs to the samples and the working solution should help.
GeneralRe: Code example.. Pin
David A. Gray3-Dec-16 20:16
David A. Gray3-Dec-16 20:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.