[GH-ISSUE #56] Question regarding return type for functions returning an lxw_error #48

Closed
opened 2026-05-05 11:31:06 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @utelle on GitHub (Jun 29, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/56

Originally assigned to: @jmcnamara on GitHub.

Many functions (like workbook or worksheet functions) return an lxw_error according to the documentation. However, the declared return type is uint8_t for the workbook functions resp. int8_t for the worksheet functions.

At the moment I have to use explicit type casts in my C++ application to avoid compiler warnings, when handling the error code returned from those functions.

Wouldn't it be better (and more logical and consistent) to use the enum type lxw_error as the return type for the functions in libxlsxwriter that return an lxw_error?

Originally created by @utelle on GitHub (Jun 29, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/56 Originally assigned to: @jmcnamara on GitHub. Many functions (like `workbook` or `worksheet` functions) return an `lxw_error` according to the documentation. However, the declared return type is `uint8_t` for the `workbook` functions resp. `int8_t` for the `worksheet` functions. At the moment I have to use explicit type casts in my C++ application to avoid compiler warnings, when handling the error code returned from those functions. Wouldn't it be better (and more logical and consistent) to use the enum type `lxw_error` as the return type for the functions in libxlsxwriter that return an `lxw_error`?
gitea-mirror 2026-05-05 11:31:06 -06:00
Author
Owner

@jmcnamara commented on GitHub (Jun 29, 2016):

Hi Ulrich,

I meant to do that when I was refactoring the error codes. I'll fix that soon.

Regards,

John

<!-- gh-comment-id:229294028 --> @jmcnamara commented on GitHub (Jun 29, 2016): Hi Ulrich, I meant to do that when I was refactoring the error codes. I'll fix that soon. Regards, John
Author
Owner

@utelle commented on GitHub (Jun 29, 2016):

Great news. Thanks.

<!-- gh-comment-id:229294689 --> @utelle commented on GitHub (Jun 29, 2016): Great news. Thanks.
Author
Owner

@jmcnamara commented on GitHub (Jun 29, 2016):

Also, just to be sure I resolve this issue can you provide a small example program that generates the warning.

<!-- gh-comment-id:229320783 --> @jmcnamara commented on GitHub (Jun 29, 2016): Also, just to be sure I resolve this issue can you provide a small example program that generates the warning.
Author
Owner

@utelle commented on GitHub (Jun 29, 2016):

Reproducing the error message is very easy. Just a simple line like the following in a C++ application

lxw_error rc = worksheet_write_formula(worksheet, row, col, formula, NULL);

results in the following error message in VC++ 2010 (most probably in later versions, too) :

xlsxwriter_wrapper.cpp(210): error C2440: 'initializing' : cannot convert from 'int8_t' to 'lxw_error'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

According to the MSDN documentation an explicit cast is required to convert from an integral type to an enumeration type.

<!-- gh-comment-id:229366002 --> @utelle commented on GitHub (Jun 29, 2016): Reproducing the error message is very easy. Just a simple line like the following in a C++ application ``` lxw_error rc = worksheet_write_formula(worksheet, row, col, formula, NULL); ``` results in the following error message in VC++ 2010 (most probably in later versions, too) : ``` xlsxwriter_wrapper.cpp(210): error C2440: 'initializing' : cannot convert from 'int8_t' to 'lxw_error' Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast) ``` According to the [MSDN documentation](https://msdn.microsoft.com/en-us/library/2dzy4k6e.aspx) an explicit cast is required to convert from an integral type to an enumeration type.
Author
Owner

@jmcnamara commented on GitHub (Jul 3, 2016):

Hi,

I've changed the return type of all public functions to lxw_error and refactored the code internally to always return it.

You can try it when you get a chance.

Also, It would be useful if you could upload a sample MSVC 2010 project to GitHub to help anyone else who is trying to get it working. Could you do that? It doesn't have to be as elaborate as the MSVCLibXlsxWriter example: https://github.com/jmcnamara/MSVCLibXlsxWriter

John

<!-- gh-comment-id:230153093 --> @jmcnamara commented on GitHub (Jul 3, 2016): Hi, I've changed the return type of all public functions to `lxw_error` and refactored the code internally to always return it. You can try it when you get a chance. Also, It would be useful if you could upload a sample MSVC 2010 project to GitHub to help anyone else who is trying to get it working. Could you do that? It doesn't have to be as elaborate as the MSVCLibXlsxWriter example: https://github.com/jmcnamara/MSVCLibXlsxWriter John
Author
Owner

@utelle commented on GitHub (Jul 3, 2016):

Great. I'll test it within the next few days.

I'm currently working on a wxWidgets wrapper for libxlsxwriter. I intend to publish it on GitHub in the not too far future. A sample will certainly be included, too.

I have a few more issues with the libxlsxwriter code, nothing serious (maybe partially again just MSVC 2010 related), but nevertheless I will open another issue for them.

<!-- gh-comment-id:230165493 --> @utelle commented on GitHub (Jul 3, 2016): Great. I'll test it within the next few days. I'm currently working on a wxWidgets wrapper for libxlsxwriter. I intend to publish it on GitHub in the not too far future. A sample will certainly be included, too. I have a few more issues with the libxlsxwriter code, nothing serious (maybe partially again just MSVC 2010 related), but nevertheless I will open another issue for them.
Author
Owner

@utelle commented on GitHub (Jul 4, 2016):

I removed the explicit lxw_error type casts from my own code ... and the code compiles flawlessly.

Great. Thanks. Keep up the good work.

<!-- gh-comment-id:230287544 --> @utelle commented on GitHub (Jul 4, 2016): I removed the explicit `lxw_error` type casts from my own code ... and the code compiles flawlessly. Great. Thanks. Keep up the good work.
Author
Owner

@jmcnamara commented on GitHub (Jul 4, 2016):

Fixed in release 0.4.0. Thanks for the report.

<!-- gh-comment-id:230363746 --> @jmcnamara commented on GitHub (Jul 4, 2016): Fixed in release 0.4.0. Thanks for the report.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#48
No description provided.