ruby-0.49 missing/strtoul.c 源码分析

本文通过一个简单的示例程序深入分析了strtoul函数的工作原理。作者通过调试和代码阅读,逐步揭示了该函数如何将字符串转换为无符号长整型数,并重点解析了一段关键代码片段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

strtol.c--->strtoul.c
因为上面的文件用到了strtoul.c,所以就直接分析这个文件。
说实话,还是调试时,看代码较快。我于是写了一个main
int main()
{
 char *s="0123";
 long  num;
 int c;
 c=strtoul(s,0,8);
 printf("%ld\n",c);
}
再编译,然后执行。得到结果,再回过头来,看代码,发现有一段:
    if (base == 8) {
 for ( ; ; p += 1) {
     digit = *p - '0';
     if (digit > 7) {
  break;
     }
     result = (result << 3) + digit;
     anyDigits = 1;
 }
不过,anyDigits这个变量不知道它的用途。一想,先过吧,读程序,最关键的是要知道这段程序的用途,至于具体实现,慢慢看吧。
/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_chip_open': core.c:(.text+0x60): undefined reference to `__lstat64_time64' core.c:(.text+0x82): undefined reference to `__stat64_time64' /opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '256', this reader only handles version 2, 3 and 4 information. core.c:(.text+0x1c6): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_update': core.c:(.text+0x2ea): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `line_request_values': core.c:(.text+0x504): undefined reference to `__ioctl_time64' /opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `line_request_event_single': core.c:(.text+0x6e0): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_get_value_bulk': core.c:(.text+0x942): undefined reference to `__ioctl_time64' /opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '55303', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o):core.c:(.text+0x968): more undefined references to `__ioctl_time64' follow /opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '6656', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_event_wait_bulk': core.c:(.text+0xf30): undefined reference to `__ppoll64' /opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-helpers.o): In function `gpiod_chip_open_lookup': helpers.c:(.text+0x178): undefined reference to `__isoc23_strtoul' collect2: 错误: ld 返回 1 make: *** [Makefile:63:build/bin/demo] 错误 1
06-02
/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_chip_open': core.c:(.text+0x60): undefined reference to `__lstat64_time64' core.c:(.text+0x82): undefined reference to `__stat64_time64' /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '256', this reader only handles version 2, 3 and 4 information. core.c:(.text+0x1c6): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_update': core.c:(.text+0x2ea): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `line_request_values': core.c:(.text+0x504): undefined reference to `__ioctl_time64' /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `line_request_event_single': core.c:(.text+0x6e0): undefined reference to `__ioctl_time64' ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_get_value_bulk': core.c:(.text+0x942): undefined reference to `__ioctl_time64' /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '55303', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o):core.c:(.text+0x968): more undefined references to `__ioctl_time64' follow /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '6656', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-core.o): In function `gpiod_line_event_wait_bulk': core.c:(.text+0xf30): undefined reference to `__ppoll64' /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information. ./gpio/source/lib/libgpiod.a(libgpiod_la-helpers.o): In function `gpiod_chip_open_lookup': helpers.c:(.text+0x178): undefined reference to `__isoc23_strtoul' collect2: 错误: ld 返回 1 make: *** [Makefile:63:build/bin/demo] 错误 1 sed@sed-VMware-Virtual-Platform:~/gui/linux$
06-02
D:/esp32_C3/vendor_0.1.5/main/main.c: In function 'uart_select_mode': D:/esp32_C3/vendor_0.1.5/main/main.c:16:15: error: implicit declaration of function 'uart_read_bytes' [-Wimplicit-function-declaration] 16 | int len = uart_read_bytes(UART_NUM_0, (uint8_t*)buffer, sizeof(buffer)-1, pdMS_TO_TICKS(5000)); | ^~~~~~~~~~~~~~~ D:/esp32_C3/vendor_0.1.5/main/main.c:16:31: error: 'UART_NUM_0' undeclared (first use in this function) 16 | int len = uart_read_bytes(UART_NUM_0, (uint8_t*)buffer, sizeof(buffer)-1, pdMS_TO_TICKS(5000)); | ^~~~~~~~~~ D:/esp32_C3/vendor_0.1.5/main/main.c:16:31: note: each undeclared identifier is reported only once for each function it appears in D:/esp32_C3/vendor_0.1.5/main/main.c:20:13: error: implicit declaration of function 'strstr' [-Wimplicit-function-declaration] 20 | if (strstr(buffer, "MODE:PROVISIONER")) { | ^~~~~~ D:/esp32_C3/vendor_0.1.5/main/main.c:10:1: note: include '<string.h>' or provide a declaration of 'strstr' 9 | #include "heartbeat.h" +++ |+#include <string.h> 10 | D:/esp32_C3/vendor_0.1.5/main/main.c:20:13: warning: incompatible implicit declaration of built-in function 'strstr' [-Wbuiltin-declaration-mismatch] 20 | if (strstr(buffer, "MODE:PROVISIONER")) { | ^~~~~~ D:/esp32_C3/vendor_0.1.5/main/main.c:20:13: note: include '<string.h>' or provide a declaration of 'strstr' [1383/1392] Performing configure step for 'bootloader' -- Found Git: E:/espidf/espressif/tools/idf-git/2.39.2/cmd/git.exe (found version "2.39.2.windows.1") -- The C compiler identification is GNU 14.2.0 -- The CXX compiler identification is GNU 14.2.0 -- The ASM compiler identification is GNU -- Found assembler: E:/espidf/espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: E:/espidf/espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: E:/espidf/espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/riscv32-esp-elf-g++.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Building ESP-IDF components for target esp32c3 -- Project sdkconfig file D:/esp32_C3/vendor_0.1.5/sdkconfig -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/riscv/ld/rom.api.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/soc/esp32c3/ld/esp32c3.peripherals.ld -- Bootloader project name: "bootloader" version: 1 -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.api.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.bt_funcs.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.libgcc.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.version.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/bootloader/subproject/main/ld/esp32c3/bootloader.ld -- Adding linker script E:/espidf/v5.4.1/esp-idf/components/bootloader/subproject/main/ld/esp32c3/bootloader.rom.ld -- Components: bootloader bootloader_support efuse esp_app_format esp_bootloader_format esp_common esp_hw_support esp_rom esp_security esp_system esptool_py freertos hal log main micro-ecc newlib partition_table riscv soc spi_flash -- Component paths: E:/espidf/v5.4.1/esp-idf/components/bootloader E:/espidf/v5.4.1/esp-idf/components/bootloader_support E:/espidf/v5.4.1/esp-idf/components/efuse E:/espidf/v5.4.1/esp-idf/components/esp_app_format E:/espidf/v5.4.1/esp-idf/components/esp_bootloader_format E:/espidf/v5.4.1/esp-idf/components/esp_common E:/espidf/v5.4.1/esp-idf/components/esp_hw_support E:/espidf/v5.4.1/esp-idf/components/esp_rom E:/espidf/v5.4.1/esp-idf/components/esp_security E:/espidf/v5.4.1/esp-idf/components/esp_system E:/espidf/v5.4.1/esp-idf/components/esptool_py E:/espidf/v5.4.1/esp-idf/components/freertos E:/espidf/v5.4.1/esp-idf/components/hal E:/espidf/v5.4.1/esp-idf/components/log E:/espidf/v5.4.1/esp-idf/components/bootloader/subproject/main E:/espidf/v5.4.1/esp-idf/components/bootloader/subproject/components/micro-ecc E:/espidf/v5.4.1/esp-idf/components/newlib E:/espidf/v5.4.1/esp-idf/components/partition_table E:/espidf/v5.4.1/esp-idf/components/riscv E:/espidf/v5.4.1/esp-idf/components/soc E:/espidf/v5.4.1/esp-idf/components/spi_flash -- Configuring done (11.1s) -- Generating done (0.1s) -- Build files have been written to: D:/esp32_C3/vendor_0.1.5/build/bootloader ninja: build stopped: subcommand failed. * 终端进程“e:\espidf\espressif\tools\ninja\1.12.1\ninja.EXE”已终止,退出代码: 1。
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值