Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output Pointer #1492

Closed
dai-2584 opened this issue Mar 26, 2020 · 5 comments
Closed

How to output Pointer #1492

dai-2584 opened this issue Mar 26, 2020 · 5 comments

Comments

@dai-2584
Copy link

dai-2584 commented Mar 26, 2020

int nP = 3;
SPDLOG_LOGGER_INFO(g_pLogger, "&nP={}", &nP);

core.h:902:5: error: static assertion failed: formatting of non-void pointers is disallowed
static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");

How to output a Pointer?

@tt4g
Copy link
Contributor

tt4g commented Mar 26, 2020

spdlog use fmt library to format argument at runtime.
You can use fmt::ptr():

int nP = 3;
SPDLOG_LOGGER_INFO(g_pLogger, "&nP={}", fmt::ptr(&nP));

@dai-2584
Copy link
Author

OK , thank you!

@caibf
Copy link

caibf commented Sep 28, 2021

Code:

HWND hwnd_child = viewer->GetWindowId();
KL_LOGGER_DEBUG("Create the visualizer viewer({}).", fmt::ptr(hwnd_child));

Output:
Create the visualizer viewer(0x1.2003275e-317).

@tt4g Why the result isn't the pointer address?

@tt4g
Copy link
Contributor

tt4g commented Sep 28, 2021

@caibf Set pointer syntax p.
https://fmt.dev/8.0.0/syntax.html

 HWND hwnd_child = viewer->GetWindowId();
- KL_LOGGER_DEBUG("Create the visualizer viewer({}).", fmt::ptr(hwnd_child));
+ KL_LOGGER_DEBUG("Create the visualizer viewer({:p}).", fmt::ptr(hwnd_child));

And it is recommended that this question be asked in the fmt repository.

@caibf
Copy link

caibf commented Sep 28, 2021

I have tried this, still the same result. Maybe the fmt version(I use spdlog 1.5.0, depends on fmt 6.1.2) problem.

But make a simple demo, result it's ok.

double elapsed_time = 0;
HWND hwnd_child = (HWND)&elapsed_time;
KL_LOGGER_DEBUG("Create the visualizer viewer({}).", fmt::ptr(hwnd_child));
KL_LOGGER_DEBUG("Create the visualizer viewer({:p}).", fmt::ptr(hwnd_child));

Output:
Create the visualizer viewer(0xef372ff6e8).
Create the visualizer viewer(0xef372ff6e8).

And it is recommended that this question be asked in the fmt repository.

OK. I will move this question to its repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants