Jump to content

указатель на начало секции


Дмитрий239
 Share

Recommended Posts

Создал секцию:

SECTIONS {
    .rodata : {
        . = ALIGN(16);
         _start_cmdList = .;
         *(.cmdList)
         KEEP(*(.cmdList))
         _stop_cmdList = .;
    }
}

объявил структуру и указатель на начало:

typedef struct
{
    const char *cmdName;
    const void (*const commandVoid)(uint8_t, char *[], char[]);
} CommandHandler;
 
extern const CommandHandler _start_cmdList[];

для теста занёс одну функцию:

const void kek(uint8_t argc, char *argv[], char answ[])
{
    strcpy_P(answ, PSTR("wow"));
}
static PROGMEM const char __attribute__((__used__)) kekAlias[] = "lol";
const CommandHandler __attribute__((section(".cmdList"))) __attribute__((__used__)) CMDHandler_kek = {.cmdName = kekAlias, .commandVoid = kek};

и проверяю:

	const CommandHandler *in = &_start_cmdList[0];
    const CommandHandler *out = &CMDHandler_kek;
    if (in == out)
        uart.println(F("ok"));
    uart.println((unsigned int)(in), HEX);
    uart.println((unsigned int)(out), HEX);
    uart.println((unsigned int)out->cmdName);
    uart.println((unsigned int)out->commandVoid);
    uart.println((unsigned int)in->cmdName);
    uart.println((unsigned int)in->commandVoid);

Выводит:
1560
1560
124
801
12800
0

МК атмега168.

Platform IO
Avr gcc 11
Линкер скрипт стандартный, с добавкой сверху

Вопрос: как получить первый элемент массива в секции?

Link to comment
Share on other sites

Реклама: ООО ТД Промэлектроника, ИНН: 6659197470, Тел: 8 (800) 1000-321

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...