store char*

N

Nezhate

I have a function like this
char * function (int input)
static char array1 [sizeof (input) * 8 + 1];

......
 
J

James Kuyper

Nezhate said:
I have a function like this
char * function (int input)
static char array1 [sizeof (input) * 8 + 1];

.....

No, you do not have a function. You have a syntax error. The simplest
correction would probably be to add either a ';' or a '{' somewhere
between the end of the first line and the start of the second line,
depending upon whether you intended to declare 'function', or define it.
There are many other possibilities; only you can know which one applies.

You haven't asked a question. If you had asked a question, you probably
didn't provide enough information to allow anyone to answer it.

If your question is about code which failed, you should provide a
complete, compilable program which is as short as possible while
demonstrating the problem. Cut and paste that program directly into your
message, without any modifications. Did you run into problems during
compilation, linking, or execution of your program? What results did you
expect? What results did you get? If you got an error message, or any
other unexpected output, please cut and paste the exact contents of that
error message into your message.
 
M

Mark B [Diputsur]

Jensen Somers said:
James said:
Nezhate said:
I have a function like this
char * function (int input)
static char array1 [sizeof (input) * 8 + 1];

.....

No, you do not have a function. You have a syntax error. The simplest
correction would probably be to add either a ';' or a '{' somewhere
between the end of the first line and the start of the second line,
depending upon whether you intended to declare 'function', or define it.
There are many other possibilities; only you can know which one applies.

Addition: if you are using a compiler < C99 (such as Visual Studio to
compile C code) your code will not compile because you are trying to
create a variable sized array which is not supported. Using Visual Studio
the size of your array should be known at compile time. (Unless you are
allocating the memory yourself.)

He's using the sizeof operator ... are you claiming that the size of an
integer
isn't known until runtime?
 
S

s0suk3

James said:
Nezhate said:
I have a function like this
char * function (int input)
static char array1 [sizeof (input) * 8 + 1];
.....
No, you do not have a function. You have a syntax error. The simplest
correction would probably be to add either a ';' or a '{' somewhere
between the end of the first line and the start of the second line,
depending upon whether you intended to declare 'function', or define it..
There are many other possibilities; only you can know which one applies..

Addition: if you are using a compiler < C99 (such as Visual Studio to
compile C code) your code will not compile because you are trying to
create a variable sized array which is not supported. Using Visual
Studio the size of your array should be known at compile time. (Unless
you are allocating the memory yourself.)

You mean a "variable-length array." But no, that code doesn't create a
VLA, because a sizeof expression can be used as a compile-time
constant.

Sebastian
 
V

vippstar

James said:
Nezhate said:
I have a function like this
char * function (int input)
static char array1 [sizeof (input) * 8 + 1];
.....
No, you do not have a function. You have a syntax error. The simplest
correction would probably be to add either a ';' or a '{' somewhere
between the end of the first line and the start of the second line,
depending upon whether you intended to declare 'function', or define it.
There are many other possibilities; only you can know which one applies.

Addition: if you are using a compiler < C99 (such as Visual Studio to
compile C code) your code will not compile because you are trying to
create a variable sized array which is not supported. Using Visual
Studio the size of your array should be known at compile time. (Unless
you are allocating the memory yourself.)

sizeof is replaced by an integer in later TPs, so it's not a VLA.
 
M

MN

sorry for this post!
I started to write my question and accidentally I pushed the tab key
and my post was added in this group. So don't reply to this post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top