[ERROR] Expected expression before ';' token

D

Dariusz My¶liwiec

Hello!
GCC compiler is showing me this error:
"error: expected expression before ';' token"
What's wrong here?

Code:
pixmap = malloc(sizeof(Pixel24*) * height);
for(i = 0; i < height; i++) {
pixmap = (Pixel24**); //According to the message error is in this line
}
 
I

Ian Collins

Dariusz said:
Hello!
GCC compiler is showing me this error:
"error: expected expression before ';' token"
What's wrong here?

Code:
pixmap = malloc(sizeof(Pixel24*) * height);
for(i = 0; i < height; i++) {
pixmap = (Pixel24**); //According to the message error is in this line


I'm not surprised, Pixel24 appears to be a type so you are attempting to
assign a type, Pixel24**, to pixmap. Did you intent to cast something?
 
D

Dariusz My¶liwiec

Dariusz said:
GCC compiler is showing me this error:
"error: expected expression before ';' token"
What's wrong here?


pixmap = malloc(sizeof(Pixel24*) * height);
for(i = 0; i < height; i++) {
pixmap = (Pixel24**); //According to the message error isin this line




I'm not surprised, Pixel24 appears to be a type so you are attempting to

assign a type, Pixel24**, to pixmap. Did you intent to cast something?


Thank you! Now it's working!
This line should look like this:
pixmap = (Pixel24**)malloc(sizeof(Pixel24) * width);
 
I

Ian Collins

Dariusz said:
Dariusz said:
Hello!
GCC compiler is showing me this error:
"error: expected expression before ';' token"
What's wrong here?

Code:
pixmap = malloc(sizeof(Pixel24*) * height);
for(i = 0; i < height; i++) {
pixmap = (Pixel24**); //According to the message error is in this line


I'm not surprised, Pixel24 appears to be a type so you are attempting to

assign a type, Pixel24**, to pixmap. Did you intent to cast something?


Thank you! Now it's working!
This line should look like this:
pixmap = (Pixel24**)malloc(sizeof(Pixel24) * width);


It should look more like

pixmap = malloc(sizeof(Pixel24) * width);

the cast is more trouble than it is worth!
 
T

Tim Rentsch

Ian Collins said:
Dariusz said:
Dariusz M wrote:

Hello!
GCC compiler is showing me this error:
"error: expected expression before ';' token"
What's wrong here?

Code:
pixmap = malloc(sizeof(Pixel24*) * height);
for(i = 0; i < height; i++) {
pixmap = (Pixel24**); // [error line]

I'm not surprised, Pixel24 appears to be a type so you are attempting to

assign a type, Pixel24**, to pixmap. Did you intent to cast something?


Thank you! Now it's working!
This line should look like this:
pixmap = (Pixel24**)malloc(sizeof(Pixel24) * width);


It should look more like

pixmap = malloc(sizeof(Pixel24) * width);

the cast is more trouble than it is worth!


Moreover the combination of types originally used indicates some
sort of deeper problem. This example would benefit greatly, and
moreso than simpler examples, from following the standard idiom
for malloc() calls:

pixmap = malloc( height * sizeof *pixmap );
for(i = 0; i < height; i++) {
pixmap = malloc( width * sizeof *pixmap );
...
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top