Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   [ERROR] Expected expression before ';' token (http://www.velocityreviews.com/forums/t956719-error-expected-expression-before-token.html)

Dariusz Myśliwiec 01-20-2013 09:31 AM

[ERROR] Expected expression before ';' token
 
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[i] = (Pixel24**); //According to the message error is in this line
}

Ian Collins 01-20-2013 10:05 AM

Re: [ERROR] Expected expression before ';' token
 
Dariusz Myśliwiec 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[i] = (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[i]. Did you intent to cast something?

--
Ian Collins

Dariusz Myśliwiec 01-20-2013 10:08 AM

Re: [ERROR] Expected expression before ';' token
 
On Sunday, January 20, 2013 11:05:31 AM UTC+1, Ian Collins wrote:
> Dariusz Myśliwiec 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[i] = (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[i]. Did you intent to cast something?
>
>
>
> --
>
> Ian Collins


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

Ian Collins 01-20-2013 10:12 AM

Re: [ERROR] Expected expression before ';' token
 
Dariusz Myśliwiec wrote:
> On Sunday, January 20, 2013 11:05:31 AM UTC+1, Ian Collins wrote:
>> Dariusz Myśliwiec 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[i] = (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[i]. Did you intent to cast something?

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


It should look more like

pixmap[i] = malloc(sizeof(Pixel24) * width);

the cast is more trouble than it is worth!

--
Ian Collins

Tim Rentsch 01-20-2013 07:47 PM

Re: [ERROR] Expected expression before ';' token
 
Ian Collins <ian-news@hotmail.com> writes:

> Dariusz M wrote:
>> On Sunday, January 20, 2013 11:05:31 AM UTC+1, Ian Collins wrote:
>>> 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[i] = (Pixel24**); // [error line]
>>>
>>> I'm not surprised, Pixel24 appears to be a type so you are attempting to
>>>
>>> assign a type, Pixel24**, to pixmap[i]. Did you intent to cast something?

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

>
> It should look more like
>
> pixmap[i] = 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[i] = malloc( width * sizeof *pixmap[i] );
...


All times are GMT. The time now is 09:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.