Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@cbracken
Copy link
Member

We currently use a mix of C standard includes (e.g. limits.h) and their
C++ variants (e.g. climits). This migrates to a consistent style for all
cases where the C++ variants are acceptable, but leaves the C
equivalents in place where they are required, such as in the embedder
API and other headers that may be used from C.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


#include "flutter/fml/build_config.h"

#if defined(OS_WIN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This symbol is only required on Windows (for M_PI etc.) and this is the only place we actually wrap it in a platform check, but also the place we benefit least from doing so (unittest). We could wrap it everywhere, but figured it would be nice to keep the code consistent so people don't end up doing a mix of the two approaches.

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define _USE_MATH_DEFINES
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep this with the header?

(Applies to the same change in other files as well.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a bunch of cases, we pull in cmath without defining this; if the first include is via something transitively included via canvas.h, we end up getting it without M_PI etc.

There are a couple options: one is that everywhere we include cmath, we define this. Another is the approach of defining this symbol before the first include in a given file, which feels safer, despite the fact it would be nice to keep them side-by-side. Thoughts/preferences?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add it as a define in GN instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Will take a look; that avoids cluttering the code with this altogether. It's not obvious to readers at first blush why this is there until you look up what the define does and it's not anything insightful when you do finally find out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #21166

@cbracken cbracken added Work in progress (WIP) Not ready (yet) for review! and removed Work in progress (WIP) Not ready (yet) for review! labels Sep 11, 2020
We currently use a mix of C standard includes (e.g. limits.h) and their
C++ variants (e.g. climits). This migrates to a consistent style for all
cases where the C++ variants are acceptable, but leaves the C
equivalents in place where they are required, such as in the embedder
API and other headers that may be used from C.
@cbracken cbracken merged commit 16b900b into flutter:master Sep 12, 2020
@cbracken cbracken deleted the include-cleanup-cxxincludes branch September 12, 2020 00:10
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants