Skip to content

Commit

Permalink
Avoid gcc warning about a templated packed structure
Browse files Browse the repository at this point in the history
Seen in at least gcc 14. Code still seems to work ok
but not fully tested!!
  • Loading branch information
AnotherJohnH committed Jan 5, 2025
1 parent 73bdf3a commit e600ce5
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ message("-----------------------------------------------------------------------
add_subdirectory(GUI)
add_subdirectory(STB)
add_subdirectory(PLT)
add_subdirectory(USB)

#-------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

targets = native
targets = native rpipico2 rpipico

all: $(targets)

Expand Down
10 changes: 10 additions & 0 deletions USB/Audio/MIDIStreaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ struct JackOutDescr : public Descr

uint8_t jack_idx{0};

#if defined(__GNUC__) && !defined(__clang__)
}; // XXX gcc 14 is not happy with packing this structure
// we assume everything is still ok?
#else
} __attribute__((__packed__));
#endif


template <unsigned N>
Expand All @@ -124,7 +129,12 @@ struct CSEndPointDescr : public Descr
uint8_t num_emb_midi_jack{N};
uint8_t assoc_jack_id[N] = {};

#if defined(__GNUC__) && !defined(__clang__)
}; // XXX gcc 14 is not happy with packing this structure
// we assume everything is still ok?
#else
} __attribute__((__packed__));
#endif


struct EndPointDescr : public Descr
Expand Down
23 changes: 23 additions & 0 deletions USB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2024 John D. Haughton
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#-------------------------------------------------------------------------------

add_subdirectory(test)
33 changes: 33 additions & 0 deletions USB/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2025 John D. Haughton
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#-------------------------------------------------------------------------------

if(${PLT_NATIVE})

add_executable(test_USB
testMain.cpp
testAudio.cpp)

target_link_libraries(test_USB STB)

add_test(NAME test_USB COMMAND test_USB)

endif()
34 changes: 34 additions & 0 deletions USB/test/testAudio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// Copyright (c) 2025 John D. Haughton
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//------------------------------------------------------------------------------

#include "USB/Audio/MIDIStreaming.h"

#include "STB/Test.h"

TEST(USB_Audio, structure_sizes)
{
EXPECT_EQ(size_t(7), sizeof(USB::MS::HeaderDescr) - sizeof(USB::Descr));
EXPECT_EQ(size_t(6), sizeof(USB::MS::JackInDescr) - sizeof(USB::Descr));
EXPECT_EQ(size_t(7 + 2 * 2), sizeof(USB::MS::JackOutDescr<2>) - sizeof(USB::Descr));
EXPECT_EQ(size_t(4 + 2), sizeof(USB::MS::CSEndPointDescr<2>) - sizeof(USB::Descr));
EXPECT_EQ(size_t(9), sizeof(USB::MS::EndPointDescr) - sizeof(USB::Descr));
}
25 changes: 25 additions & 0 deletions USB/test/testMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// Copyright (c) 2025 John D. Haughton
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//------------------------------------------------------------------------------

#include "STB/Test.h"

TEST_MAIN

0 comments on commit e600ce5

Please sign in to comment.