I have this legacy macro
#define ASYNC_FUNCTION(x)
void x(void) {
static void internal ## x (ASYNCIOCB *);
ASYNCIOCB *aiocb = AcquireAsyncIOCB();
CallAsyncNativeFunction_md(aiocb, internal ## x);
}
static void internal ## x (ASYNCIOCB *aiocb)
followed by this one
#define ASYNC_FUNCTION_START(x) ASYNC_FUNCTION(x) {
#define ASYNC_FUNCTION_END ASYNC_resumeThread(); }
And their use looks like this:
ASYNC_FUNCTION_START(Occasional_function_name)
{
//actual stuff
}
ASYNC_FUNCTION_END
It compiles fine with cl, but gcc gives
invalid storage class for function ‘internalOccasional_function_name’
static void internal##x (ASYNCIOCB *);
^
I tried to expand them all just to see what it becomes and found nothing broken. I also searched for unclosed curved brackets in the file, and found other macros like this
#define Foo_Bar1() {
extern int foo;
int bar = foo;
if (condition) {
Bar_Foo();
}
#define Foo_Bar2()
if (condibar != footion1){
AbortAsyncIOCB(aiocb);
return;
}
if (condition) {
Bar_Foo();
}
}
No other headers are included, so other than that last macro looking weird, I couldn’t find any obvious errors. I’m using cygwin and I’m fairly clueless.
- Forum
- General Programming Boards
- C Programming
- Invalid storage class for function
-
10-15-2012
#1
Registered User
Invalid storage class for function
Hey again,
So this time I am trying to make a function to call twice instead of repeating the chunk of code twice. When I was not using the function the code worked fine so it seems like I set up the function wrong. Here is what I have when the ‘invalid storage class’ error occurs:Code:
static void getAndPrint (char mainFile[], FILE *search); void getAndPrint (char mainFile[], FILE *search) { char data1[256]; char data2[256]; char line[256]; char term[12] = "FindMe"; char dest[] = "/home/user/Desktop/folder/"; strcat (dest, mainFile); FILE *data; data = fopen (dest, "w"); if (search != NULL) { while (fgets (line, sizeof(line), search) { if ( strstr (line, term) != NULL) { fgets (data1 -2, sizeof(data1), search); fprintf (data, "%sn", data1); fgets (data2 -2, sizeof(data2), search); fprintf (data, "%sn", data2); } } } fclose(search); }
Thank you for your time.
Dominic
-
10-15-2012
#2
C++ Witch
On which line does your compiler report that error and what is the exact error message?
My guess would be that the problem has something to do with you forward declaring getAndPrint to be static, but as I don’t normally forward declare my static functions, I don’t dare to say that that is the problem without some investigation of my own.
Last edited by laserlight; 10-15-2012 at 10:14 AM.
Originally Posted by Bjarne Stroustrup (2000-10-14)
I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. «Finding the smallest program that demonstrates the error» is a powerful debugging tool.
Look up a C++ Reference and learn How To Ask Questions The Smart Way
-
10-15-2012
#3
and the hat of int overfl
> fgets (data1 -2, sizeof(data1), search);
What are you hoping to achieve with this out of bound pointer to your buffer?
-
10-15-2012
#4
Registered User
From the example code, it would be on line 3 after I have made the prototype. The error is «invalid storage class for function ‘getAndPrint’ «. If I dont declare the protoype static I get errors: «colficting types for ‘getAndPrint», «previous implicit declaration of ‘getAndPrint’ was here», «static declaration of ‘getAndPrint’ follows non-static declaratation».
-
10-15-2012
#5
— — — — — — — —
Do you just need to include the word «static» in front of your function definition (and not just in the prototype)?
Other problems:
Since dest is defined like this:
char dest[] = «/home/user/Desktop/folder/»;
it does not have the storage to concatenate more chars into:
strcat (dest, mainFile);
Try this instead:
char dest[100] = «/home/user/Desktop/folder/»;
and use strncat to prevent possible buffer overflow
strncat (dest, mainFile, sizeof dest — strlen(dest) — 1);And in your fgets, why are you subtracting 2 from data1 and data2? That’s undefined.
The cost of software maintenance increases with the square of the programmer’s creativity. — Robert D. Bliss
-
10-15-2012
#6
C++ Witch
Also, you seem to be confused between the search and data FILE pointers.
Originally Posted by InicDominus
From the example code, it would be on line 3 after I have made the prototype. The error is «invalid storage class for function ‘getAndPrint’ «. If I dont declare the protoype static I get errors: «colficting types for ‘getAndPrint», «previous implicit declaration of ‘getAndPrint’ was here», «static declaration of ‘getAndPrint’ follows non-static declaratation».
It might be good for you to reduce your program to the smallest and simplest program that you expect to compile but which demonstrates this problem, and post it. As it stands, it is possible to take your example code, fix an unrelated syntax error, then have a compilable (though incorrect) program.
Originally Posted by Bjarne Stroustrup (2000-10-14)
I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. «Finding the smallest program that demonstrates the error» is a powerful debugging tool.
Look up a C++ Reference and learn How To Ask Questions The Smart Way
-
10-15-2012
#7
Registered User
Salem, it gathers a whole line of data from a file after finding a keyword. I know it may be sloppy as I have never used C before but it works fine.
-
10-15-2012
#8
C++ Witch
Originally Posted by InicDominus
I know it may be sloppy as I have never used C before but it works fine.
It may appear to work fine, yet still be horribly wrong. One of the effects of undefined behaviour is that the code works perfectly until the moment that you really need it to work perfectly (e.g., when your program is being graded or when it is being demonstrated to the client).
Originally Posted by Bjarne Stroustrup (2000-10-14)
I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. «Finding the smallest program that demonstrates the error» is a powerful debugging tool.
Look up a C++ Reference and learn How To Ask Questions The Smart Way
-
10-15-2012
#9
and the hat of int overfl
> I know it may be sloppy as I have never used C before but it works fine.
So said the blind man who ran across the road, and survived the first time he tried it.Yes, it is sloppy, and you’ll get your ass handed to you on a plate at some point in the form of a segfault.
Feel free to carry on as you are, until I tell you to add
#include <I_told_you_so.h>Never make the mistake of assuming «works» == «bug free» when it comes to C programming. All sorts of crap can seem to «work» in the beginning, only to crash and burn later on.
-
10-15-2012
#10
Registered User
Alright thank you for the advice. I will go fix that.
Popular pages
- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish
Recent additions
- How to create a shared library on Linux with GCC — December 30, 2011
- Enum classes and nullptr in C++11 — November 27, 2011
- Learn about The Hash Table — November 20, 2011
- Rvalue References and Move Semantics in C++11 — November 13, 2011
- C and C++ for Java Programmers — November 5, 2011
- A Gentle Introduction to C++ IO Streams — October 10, 2011
Similar Threads
-
Replies: 4
Last Post: 10-16-2011, 02:42 AM
-
Replies: 5
Last Post: 11-06-2008, 04:07 PM
-
Replies: 12
Last Post: 12-20-2005, 01:14 PM
-
Replies: 2
Last Post: 06-01-2003, 02:44 PM
-
Replies: 5
Last Post: 04-15-2003, 09:54 PM
Tags for this Thread
У меня есть устаревший макрос
#define ASYNC_FUNCTION(x)
void x(void) {
static void internal ## x (ASYNCIOCB *);
ASYNCIOCB *aiocb = AcquireAsyncIOCB();
CallAsyncNativeFunction_md(aiocb, internal ## x);
}
static void internal ## x (ASYNCIOCB *aiocb)
За которым следует этот
#define ASYNC_FUNCTION_START(x) ASYNC_FUNCTION(x) {
#define ASYNC_FUNCTION_END ASYNC_resumeThread(); }
И их использование выглядит так:
ASYNC_FUNCTION_START(Occasional_function_name)
{
//actual stuff
}
ASYNC_FUNCTION_END
Он отлично компилируется с cl, но gcc дает
invalid storage class for function ‘internalOccasional_function_name’
static void internal##x (ASYNCIOCB *);
^
Я попытался расширить их все, чтобы посмотреть, что из этого получится, и не нашел ничего сломанного. Я также искал незакрытые изогнутые скобки в файле и нашел другие макросы, подобные этому
#define Foo_Bar1() {
extern int foo;
int bar = foo;
if (condition) {
Bar_Foo();
}
#define Foo_Bar2()
if (condibar != footion1){
AbortAsyncIOCB(aiocb);
return;
}
if (condition) {
Bar_Foo();
}
}
Никакие другие заголовки не включены, поэтому кроме этого последнего макроса, выглядящего странно, я не смог найти никаких очевидных ошибок. Я использую cygwin и довольно невежественен.
2 ответа
Лучший ответ
Вы не можете объявить статическую функцию внутри другой. Вам необходимо разместить объявление за пределами void(x)
:
#define ASYNC_FUNCTION(x)
static void internal ## x (ASYNCIOCB *);
void x(void) {
ASYNCIOCB *aiocb = AcquireAsyncIOCB();
CallAsyncNativeFunction_md(aiocb, internal ## x);
}
static void internal ## x (ASYNCIOCB *aiocb)
Затем, если вы запустите исходный код только через препроцессор через gcc -E
, вы получите что-то вроде этого (добавлен дополнительный интервал):
static void internalOccasional_function_name (ASYNCIOCB *);
void Occasional_function_name(void)
{
ASYNCIOCB *aiocb = AcquireAsyncIOCB();
CallAsyncNativeFunction_md(aiocb, internalOccasional_function_name);
}
static void internalOccasional_function_name (ASYNCIOCB *aiocb)
{
{
int a=1;
}
ASYNC_resumeThread();
}
7
dbush
25 Май 2016 в 19:37
В языке C объявления локальных функций могут дополнительно включать спецификатор класса хранения extern
. Это единственный спецификатор класса хранения, который может иметь объявление локальной функции. Никакие другие спецификаторы класса хранения не допускаются.
6.7.1 / 7:
Объявление идентификатора функции, имеющей область видимости блока, не должно иметь явного спецификатора класса хранения, кроме extern .
1
AnT
25 Май 2016 в 19:38
Comments
msabramo
added a commit
to msabramo/linux
that referenced
this issue
Feb 29, 2012
This was referenced
Feb 29, 2012
msabramo
added a commit
to msabramo/linux
that referenced
this issue
Mar 1, 2012
…l history, DECLARE_MUTEX was renamed to DEFINE_SEMAPHORE. Older kernels like the stock kernel on Ubuntu 10.04.4 (Linux ubuntu 2.6.32-38-generic dtrace4linux#83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux) don't have DEFINE_SEMAPHORE in their headers.
Fixes dtrace4linuxGH-11.
azat
added a commit
to azat-archive/dtrace4linux
that referenced
this issue
Aug 7, 2013
I see this is happens in gdb: gdb bt: #0 taskq_dispatch2 (tq=0xffff88003712e600, func=0x0 <irq_stack_union>, arg=0x0 <irq_stack_union>, flags=0, delay=1) at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/taskq.c:263 dtrace4linux#1 0xffffffffa0369433 in timeout ( func=func@entry=0xffffffffa035c9d5 <fasttrap_pid_cleanup_cb>, arg=arg@entry=0x0 <irq_stack_union>, ticks=ticks@entry=1) at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/taskq.c:306 dtrace4linux#2 0xffffffffa035c9c0 in fasttrap_pid_cleanup () at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/fasttrap.c:505 dtrace4linux#3 0xffffffffa035cdbf in fasttrap_provider_retire (pid=<optimized out>, name=0xffffffffa037eb8f "pid", name@entry=0x140ef <Address 0x140ef out of bounds>, mprov=mprov@entry=0) at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/fasttrap.c:1713 dtrace4linux#4 0xffffffffa035ce08 in fasttrap_exec_exit (p=0xffff8800371d3b18) at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/fasttrap.c:596 dtrace4linux#5 0xffffffffa0358c09 in proc_exit_notifier (n=<optimized out>, code=<optimized out>, ptr=<optimized out>) at /usr/src/dtrace4linux/build-3.11.0-rc4+/driver/dtrace_linux.c:2020 dtrace4linux#6 0xffffffff8139b2d3 in notifier_call_chain ( nl=nl@entry=0xffffffff81634da0 <task_exit_notifier+32>, val=val@entry=0, v=v@entry=0xffff88007b62b040, nr_to_call=nr_to_call@entry=-1, nr_calls=nr_calls@entry=0x0 <irq_stack_union>) at kernel/notifier.c:93 dtrace4linux#7 0xffffffff8105824b in __blocking_notifier_call_chain ( nh=nh@entry=0xffffffff81634d80 <task_exit_notifier>, val=val@entry=0, v=0xffff88007b62b040, nr_to_call=nr_to_call@entry=-1, nr_calls=nr_calls@entry=0x0 <irq_stack_union>) at kernel/notifier.c:314 dtrace4linux#8 0xffffffff81058273 in blocking_notifier_call_chain ( nh=nh@entry=0xffffffff81634d80 <task_exit_notifier>, val=val@entry=0, v=<optimized out>) at kernel/notifier.c:325 dtrace4linux#9 0xffffffff810750f5 in profile_task_exit (task=<optimized out>) at kernel/profile.c:143 dtrace4linux#10 0xffffffff8103a3cf in do_exit () dtrace4linux#11 0xffffffff8103b87c in do_group_exit () dtrace4linux#12 0xffffffff81047522 in get_signal_to_deliver () dtrace4linux#13 0xffffffff81002176 in do_signal () dtrace4linux#14 0xffffffff810025d3 in do_notify_resume () dtrace4linux#15 <signal handler called> dtrace4linux#16 0x00007fed3818fff8 in ?? () Refs dtrace4linux#61
Hi, I face the same problem as the error message keep on say that:
libvlc.c:507:11: warning: “/*” within comment
libvlc.c:2154: error: invalid storage class for function ‘AddIntfInternal’
libvlc.c:2214: error: invalid storage class for function ‘SetLanguage’
libvlc.c:2281: error: invalid storage class for function ‘GetFilenames’
libvlc.c:2331: error: invalid storage class for function ‘Help’
libvlc.c:2363: error: invalid storage class for function ‘Usage’
libvlc.c:2647: error: invalid storage class for function ‘ListModules’
libvlc.c:2694: error: invalid storage class for function ‘Version’
libvlc.c:2773: error: invalid storage class for function ‘ConsoleWidth’
libvlc.c:2808: error: invalid storage class for function ‘VerboseCallback’
libvlc.c:2824: error: invalid storage class for function ‘InitDeviceValues’
libvlc.c:2910: error: expected declaration or statement at end of input
May I know what do you mean by missing brace?
cos I hope that can solve my problem too.
Thanks
Comment by wssoh— December 24, 2008 #
0
1
При сборке кода командой:
/opt/cross/arm-cortexa7hf-linux-gnueabi/bin/arm-cortexa7hf-linux-gnueabi-gcc -o test-bin -ltinfo test.c
Выдается следующая ошибка:
In file included from /opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/endian.h:60:0,
from /opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/sys/types.h:216,
from /opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/termcap.h:49,
from test3.c:517:
/opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/bits/byteswap.h: In function 'main':
/opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/bits/byteswap.h:44:1: error: invalid storage class for function '__bswap_32'
__bswap_32 (unsigned int __bsx)
^
/opt/cross/arm-cortexa7hf-linux-gnueabi/arm-cortexa7hf-linux-gnueabi/sysroot/usr/include/bits/byteswap.h:75:1: error: invalid storage class for function '__bswap_64'
__bswap_64 (__uint64_t __bsx)
^
Подскажите, по какой причине это происходит?
У меня по этой причине ни одна утилита/библиотека не собирается с поддержкой ncurses.
Hello fNET forum,
I am using an Kinetis MK64FX512 and trying to build an ethernet bootloader.
I have started from scratch by creating a new project on MCUXpresso and then begin to import the libraries needed. I have copied fnet_stack and fnet_application from the FNET4.6.3 package and my main has the fapp_main() and fapp_hw_init()
The issue is that when I finally import the fnet_application folder and set it in the tool setting include, I get a massive number of compiling erros such as
../CMSIS/cmsis_gcc.h:126:53: error: invalid storage class for function ‘enable_irq’
attribute((always_inline)) STATIC_INLINE void enable_irq(void)
^~~~~~~~~~~~
../CMSIS/cmsis_gcc.h:137:53: error: invalid storage class for function ‘disable_irq’
attribute((always_inline)) STATIC_INLINE void disable_irq(void)
^~~~~~~~~~~~~
../CMSIS/cmsis_gcc.h:148:57: error: invalid storage class for function ‘get_CONTROL’
attribute((always_inline)) STATIC_INLINE uint32_t get_CONTROL(void)
^~~~~~~~~~~~~
../CMSIS/cmsis_gcc.h:178:53: error: invalid storage class for function ‘set_CONTROL’
attribute((always_inline)) STATIC_INLINE void set_CONTROL(uint32_t control)
^~~~~~~~~~~~~
../CMSIS/cmsis_gcc.h:202:57: error: invalid storage class for function ‘__get_IPSR’
It continues for a lot more.
At the cmsis_gcc.h (that I have not changed) I have :
/*
brief Enable IRQ Interrupts
details Enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes./
attribute((always_inline)) STATIC_INLINE void enable_irq(void)
{
__ASM volatile («cpsie i» : : : «memory»);
}
Do you guys have any idea on what am I missing ?
Thank you very much in advance
Best regards
Stralows