整个测试程序如下:
- #include "fsl_device_registers.h"
- #include "fsl_debug_console.h"
- #include "board.h"
- #include "string.h"
- void sizeof_Test(uint8_t * test)
- {
- uint32_t i;
- for (i = 0; i < sizeof(test)/sizeof(uint8_t); i++)
- {
- PRINTF("%d ", test[i]);
- }
- PRINTF("\r\n");
- }
- void right_test(uint8_t * test, uint32_t count)
- {
- uint32_t i;
- for (i = 0; i < count; i++)
- {
- PRINTF("%d ", test[i]);
- }
- PRINTF("\r\n");
- }
- int main(void)
- {
- /* Write your code here */
- uint32_t i;
- uint8_t test1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- hardware_init();
- PRINTF("\r\nSizeof test:\r\n");
- PRINTF("\r\n-----------------Using sizeof in main-----------------\r\n");
- for (i = 0; i < sizeof(test1)/sizeof(uint8_t); i++)
- {
- PRINTF("%d ", test1[i]);
- }
- PRINTF("\r\n");
- PRINTF("\r\n------------Using sizeof in sub function--------------\r\n");
- sizeof_Test(test1);
- PRINTF("\r\n---------------------The right method-----------------\r\n");
- right_test(test1, sizeof(test1)/sizeof(uint8_t));
- /* This for loop should be replaced. By default this loop allows a single stepping. */
- for (;;) {
- ;
- }
- /* Never leave main */
- return 0;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // EOF
- ////////////////////////////////////////////////////////////////////////////////
|