[GH-ISSUE #59] Inconsistant constness of char* parameters #51

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

Originally created by @utelle on GitHub (Jul 4, 2016).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/59

Originally assigned to: @jmcnamara on GitHub.

Many libxlsxwriter functions take text strings as parameters. The constness of those string parameters is used inconsistently. While sometimes const char* is used, several functions just use char*.

In my application I have string variables declared with const char*. At least for MSVC++ 2010 passing such variables to libxlsxwriter functions often result in the compiler message

error C2664: 'worksheet_set_header' : cannot convert parameter 2 from 'const char *' to 'char *'

At the moment I have only inspected the functions defined for workbooks and worksheets. That is, the following list of affected functions might be incomplete. Here is a list of functions that use char* parameters, but IMHO should use const char* instead, because they don't manipulate the strings passed to them, but usually just create a copy using strdup:

  • worksheet_set_header
  • worksheet_set_footer
  • worksheet_set_header_opt
  • worksheet_set_footer_opt
  • workbook_set_custom_property_string
  • workbook_set_custom_property_number
  • workbook_set_custom_property_integer
  • workbook_set_custom_property_boolean
  • workbook_set_custom_property_datetime
  • workbook_get_worksheet_by_name
  • worksheet_protect
Originally created by @utelle on GitHub (Jul 4, 2016). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/59 Originally assigned to: @jmcnamara on GitHub. Many `libxlsxwriter` functions take text strings as parameters. The constness of those string parameters is used inconsistently. While sometimes `const char*` is used, several functions just use `char*`. In my application I have string variables declared with `const char*`. At least for MSVC++ 2010 passing such variables to `libxlsxwriter` functions often result in the compiler message ``` error C2664: 'worksheet_set_header' : cannot convert parameter 2 from 'const char *' to 'char *' ``` At the moment I have only inspected the functions defined for workbooks and worksheets. That is, the following list of affected functions might be incomplete. Here is a list of functions that use `char*` parameters, but IMHO should use `const char*` instead, because they don't manipulate the strings passed to them, but usually just create a copy using `strdup`: - worksheet_set_header - worksheet_set_footer - worksheet_set_header_opt - worksheet_set_footer_opt - workbook_set_custom_property_string - workbook_set_custom_property_number - workbook_set_custom_property_integer - workbook_set_custom_property_boolean - workbook_set_custom_property_datetime - workbook_get_worksheet_by_name - worksheet_protect
gitea-mirror 2026-05-05 11:31:49 -06:00
Author
Owner

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

I seem to have started with const correctness and forgot it along the way.

The char* in the API should now all be const on master.

<!-- gh-comment-id:230353573 --> @jmcnamara commented on GitHub (Jul 4, 2016): I seem to have started with const correctness and forgot it along the way. The char\* in the API should now all be const on master.
Author
Owner

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

Thanks for taking care of the issues I created today so quickly. Much appreciated.

<!-- gh-comment-id:230355358 --> @utelle commented on GitHub (Jul 4, 2016): Thanks for taking care of the issues I created today so quickly. Much appreciated.
Author
Owner

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

Fixed in release 0.4.0. Thanks for the report.

<!-- gh-comment-id:230363762 --> @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#51
No description provided.