Skip to content

Fix cute_tiled.h variable shadowing warnings on MSVC#414

Open
joshlengel wants to merge 1 commit intoRandyGaul:masterfrom
joshlengel:msvc_warnings
Open

Fix cute_tiled.h variable shadowing warnings on MSVC#414
joshlengel wants to merge 1 commit intoRandyGaul:masterfrom
joshlengel:msvc_warnings

Conversation

@joshlengel
Copy link

Hello!

I've been using the cute_tiled.h for a week or so and encountered multiple variable shadowing warnings in the strpool section when using MSVC (Visual Studio Community Edition 2022).

.\cute_tiled.h(994): warning C4456: declaration of 'data' hides previous local declaration
.\cute_tiled.h(951): note: see declaration of 'data'
.\cute_tiled.h(1044): warning C4456: declaration of 'entry' hides previous local declaration
.\cute_tiled.h(1017): note: see declaration of 'entry'
.\cute_tiled.h(1052): warning C4456: declaration of 'handle_index' hides previous local declaration
.\cute_tiled.h(1016): note: see declaration of 'handle_index'

Compiling the test_cute_tiled/main.cpp with /W4 emits three warnings about local variables being shadowed. Now, this is not really a problem but the solution is simple and negates the need to mess around with warning suppression. The pull request merely relocates the declaration of three local variables to the location they are first used at. As such, there should be hardly any difference in machine code besides possibly reducing the respective stack frames by a few bytes.

Thanks for the great library!

With kind regards,
Josh Lengel

@joshlengel joshlengel changed the title Fixed cute_tiled.h variable shadowing warnings on MSVC Fix cute_tiled.h variable shadowing warnings on MSVC Sep 9, 2025
Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

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

Perhaps introduce some brackets to have its own scope? Otherwise rename the variables if it's causing issue in MSVC.

// Allocate a new block
pool->current_block = strpool_embedded_internal_add_block( pool, size > pool->block_size ? size : pool->block_size );
data = pool->blocks[ pool->current_block ].tail;
char *data = pool->blocks[ pool->current_block ].tail;
Copy link
Contributor

Choose a reason for hiding this comment

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

ANSI C89 requires variables to be declared at the beginning of a scope.

Comment on lines 1090 to +1092

int handle_index;
strpool_embedded_internal_entry_t* entry;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

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

Successfully merging this pull request may close these issues.

2 participants