我有一个CMake脚本,其中最终的可执行文件与我自己的链接器脚本链接:
cmake_minimum_required(VERSION 3.1)
project(test_app)
set(LINKER_SCRIPT "linker.ld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf
main.cpp
startup.cpp
)
Run Code Online (Sandbox Code Playgroud)
如何使可执行文件也依赖于链接描述文件(触发链接,如果linker.ld已更改)?
我收到许多 XML 文件,其中一些文件的编码错误(例如,在 xml 标头中是 ISO-8859-1,但所有字符串都是 UTF-8,等等)
使用 xml.etree.ElementTree 进行解析,这也会读取带有编码的 xml 标头(有时是错误的)
input_element = xml.etree.ElementTree.parse("input.xml").getroot()
Run Code Online (Sandbox Code Playgroud)
我想强制使用另一种编码并从标头中忽略它。
有什么简单的方法可以做到这一点吗?
通常它没有意义并且非常不安全,但理论上只有有办法,
这是一个例子:
#include<iostream>
struct A {
uint32_t &get() {
return *reinterpret_cast<uint32_t *>(this);
}
void set(const uint32_t val) {
*this = *reinterpret_cast<const A *>(&val);
}
};
struct B : A {
uint16_t a;
uint16_t b;
void set_b(const uint32_t val) {
*this = *reinterpret_cast<const B *>(&val);
}
};
main() {
B k;
k.a = 0x1234;
k.b = 0x5678;
std::cout << std::hex << k.get() << " : " << k.a << " " << k.b << std::endl;
k.set_b(0x87654321);
std::cout << std::hex << k.get() …Run Code Online (Sandbox Code Playgroud)