Microsoft KB Archive/107432

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 15:04, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base

PRB: Inline Assembly C++ Function May Need Return Statement

Article ID: 107432

Article Last Modified on 12/2/2003


  • Microsoft C/C++ Professional Development System 7.0
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition

This article was previously published under Q107432


C++ functions containing inline assembly routines that store the return value in the AX register may need a return statement added to the function. If the function does not have a return statement, the following error is generated:

C2561: 'function name' function must return a value


To resolve this error, create a temporary variable and move the AX register to this variable for the return statement. This will work around the C++ type-checking syntax. If you are using C++ version 8.0 that ships with Visual C++ for Windows NT, then the EAX register must be used instead.

Sample Code

/* Compile options needed: none

int func(void)
  //int a;         //Remove this comment to eliminate the error.
    mov ax, 02h
    ;mov a, ax         //Remove this comment to eliminate the error.
  //return a;         //Remove this comment to eliminate the error.

void main(void)
  int a;
  a = func();

Additional query words: 7.00 8.00 8.00c 9.00 1.00 1.50 2.00

Keywords: kbprb KB107432