Skip to main content
42 events
when toggle format what by license comment
Jul 9, 2020 at 14:15 audit Triage
Jul 9, 2020 at 14:15
Jul 8, 2020 at 6:27 audit Triage
Jul 8, 2020 at 6:44
Jul 6, 2020 at 6:25 audit Triage
Jul 6, 2020 at 6:36
Jul 3, 2020 at 11:26 audit Triage
Jul 3, 2020 at 11:38
Jul 2, 2020 at 18:36 audit Triage
Jul 2, 2020 at 18:37
Jun 30, 2020 at 16:30 audit Triage
Jun 30, 2020 at 16:30
Jun 29, 2020 at 10:06 audit Triage
Jun 29, 2020 at 11:29
Jun 26, 2020 at 15:07 audit Triage
Jun 26, 2020 at 15:08
Jun 24, 2020 at 8:18 audit Triage
Jun 24, 2020 at 8:19
Jun 23, 2020 at 4:25 audit Triage
Jun 23, 2020 at 5:19
Jun 11, 2020 at 12:30 vote accept AmirSina Mashayekh
Jun 11, 2020 at 9:00 answer added AmirSina Mashayekh timeline score: 0
Jun 10, 2020 at 7:24 answer added Dan1138 timeline score: 1
Jun 9, 2020 at 13:28 comment added Déjà vu Maybe try to assign first 0x0DD2 to a long like long var = 0x0DD2;, then replace the 0x0DD2 with var? void (*a)(void) = (void (*)(void))var; That could look less strange to the compiler.
Jun 9, 2020 at 13:18 answer added Serge Ballesta timeline score: 0
Jun 9, 2020 at 13:09 comment added AmirSina Mashayekh @NateEldredge You mean I include foo.h in all projects? Good idea. I'll try it soon.
Jun 9, 2020 at 13:04 comment added Nate Eldredge @AmirSinaMashayekh: I read that comment but I'm afraid I still don't understand. Can't you define foo at an absolute address in the USB project, then use the declaration (without the definition) to call it from the main project?
Jun 9, 2020 at 13:03 comment added Alex Lop. Based on what @NateEldredge wrote, you need to reuse the same foo.h and foo.c for both projects. Create a 'shared' directory which will be used by both projects and place those files in it.
Jun 9, 2020 at 13:02 comment added Nate Eldredge There are some other notes in the compiler manual linked above that suggest that function pointers are only supported insofar as the compiler can keep track of all the functions to which the pointer might point. That would fit with the lack of an indirect jump instruction. And it might be that this tracking is only supported when those functions have names, even if there is only one of them.
Jun 9, 2020 at 13:00 comment added AmirSina Mashayekh @NateEldredge Read the third comment. If I create separate projects for bootloader, USB and main app, I can't use &foo because foo is in USB project.
Jun 9, 2020 at 12:56 comment added Nate Eldredge I don't know a lot about PIC, but a quick glance at some instruction set listings suggest that many or all PIC machines don't have an indirect jump instruction. That would make it impossible to use function pointers in a completely general way, and might explain the restrictions imposed by the compiler. Of course in this case there is only one possible target for the jump, and the compiler could optimize it into an unconditional jump, but it may not be smart enough for that.
Jun 9, 2020 at 12:50 comment added Nate Eldredge Section 5.4.5.4 of the compiler manual, page 161, seems to be saying that such casts are simply not allowed. It may be that the __at construct is the only way to call an absolute address. Can you explain, perhaps with an example, why this won't work in the application you have in mind? Maybe there will be a different approach that would work.
Jun 9, 2020 at 12:48 comment added Alex Lop. @AmirSinaMashayekh Do not put it. Since there is no definition for get_fn_p() it will fail linkage anyway but I am curious to see if the compiler generates the assembly for a();
Jun 9, 2020 at 12:46 comment added AmirSina Mashayekh @AlexLop. Where should I put the address (0xDD2) in your code? Also compiler makes error.
Jun 9, 2020 at 12:43 comment added Nate Eldredge @underscore_d: This particular compiler uses a (non-standard) dialect of C in which main is supposed to return void. This is documented at D.3.1 in the manual. So that's not the issue here.
Jun 9, 2020 at 12:40 comment added Alex Lop. Can you try to: typedef void (*fn_p)(void); ... extern fn_p get_fn_p(void); ... fn_p a = get_fn_p(); a();. Will you see the same warning?
Jun 9, 2020 at 12:40 comment added AmirSina Mashayekh @Someprogrammerdude I edited my question codes; and compiler puts foo() in correct location as I found while debugging.
Jun 9, 2020 at 12:39 comment added underscore_d main() must return int
Jun 9, 2020 at 12:36 history edited AmirSina Mashayekh CC BY-SA 4.0
updated codes
Jun 9, 2020 at 12:33 comment added Some programmer dude Now the big question: Does foo.c include foo.h? Does the compiler know about the __at(0xDD2) part when it's compiling the foo function definition (implementation)? There's a reason we usually ask for a minimal reproducible example much earlier than has now been done. And you should really ask about this latest issue in a new question, since this has really been answered.
Jun 9, 2020 at 12:22 comment added AmirSina Mashayekh @Someprogrammerdude Look at first code: void foo(void) __at(0xDD2);. I need to call foo() just by its address (0xDD2).
Jun 9, 2020 at 12:20 comment added AmirSina Mashayekh @AlexLop. Yes. Compiler says expression generates no code and debugger passes a(); line.
Jun 9, 2020 at 12:20 comment added Some programmer dude What is actually stored as this location 0x0DD2 in memory? Is it a plain function created the same way as a function inside your own code?
Jun 9, 2020 at 12:18 comment added Alex Lop. By "not working" you mean no call/jump/branch is generated by the compiler?
Jun 9, 2020 at 12:16 comment added AmirSina Mashayekh @AlexLop. Good news: Debugger runs this line and assigns address to a. Bad news: a() still not working!
Jun 9, 2020 at 12:10 comment added Alex Lop. Can you try void (* volatile a)(void) = (void (*)(void))(0x0DD2); ? Does it change anything?
Jun 9, 2020 at 12:09 comment added AmirSina Mashayekh @AlexLop. These lines could be everywhere. For now, they are in main().
Jun 9, 2020 at 12:07 comment added AmirSina Mashayekh @Lundin The function itself is OK (not optimized out at all). I want to use USB peripheral in both bootloader and application. However, if I write USB codes for both, it will take a lot of memory. I'm trying to create something like a USB partition! (put USB codes at a specific area and use it for both bootloader and main application)
Jun 9, 2020 at 12:02 history edited Some programmer dude
edited tags; edited tags
Jun 9, 2020 at 11:59 comment added Alex Lop. Can you provide a minimal context where it can be reproduced? Where exactly these lines are placed?
Jun 9, 2020 at 11:59 comment added Lundin If the function is never called, you probably have to force it to get linked with some trick in the linker script. Why should the function never get called though, is it a bootloader or something?
Jun 9, 2020 at 11:54 history asked AmirSina Mashayekh CC BY-SA 4.0