Skip to content
/ Cross Public

Visual C++ program that prints unexpected result

Notifications You must be signed in to change notification settings

Fedr/Cross

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cross

In this repository, you will find a simple Visual C++ program:

constexpr float foo(size_t itemCount) {
    return ( 10 - 4.0f * ( itemCount - 1 ) ) / float ( itemCount );
}

int main() {
    constexpr float a = foo(3);
    const float & b = foo(3);
    printf( "%g %g", a, b );
}

It shall print 0.666667 0.666667, but if it is compiled in Visual Studio 2022 version 17.6 the result is weird: 0.666667 1.

About

Visual C++ program that prints unexpected result

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages