[ERROR] Expected expression before ';' token

Discussion in 'C Programming' started by Dariusz My¶liwiec, Jan 20, 2013.

  1. 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
    }
    Dariusz My¶liwiec, Jan 20, 2013
    #1
    1. Advertising

  2. Dariusz My¶liwiec

    Ian Collins Guest

    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 = (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?

    --
    Ian Collins
    Ian Collins, Jan 20, 2013
    #2
    1. Advertising

  3. 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 = (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?
    >
    >
    >
    > --
    >
    > Ian Collins


    Thank you! Now it's working!
    This line should look like this:
    pixmap = (Pixel24**)malloc(sizeof(Pixel24) * width);
    Dariusz My¶liwiec, Jan 20, 2013
    #3
  4. Dariusz My¶liwiec

    Ian Collins Guest

    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 = (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!

    --
    Ian Collins
    Ian Collins, Jan 20, 2013
    #4
  5. Dariusz My¶liwiec

    Tim Rentsch Guest

    Ian Collins <> 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 = (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 );
    ...
    Tim Rentsch, Jan 20, 2013
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bubzilla
    Replies:
    2
    Views:
    915
    bubzilla
    Sep 25, 2006
  2. andrew browning
    Replies:
    16
    Views:
    15,464
    Artie Gold
    Mar 13, 2006
  3. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    This is an unexpected token. The expected token is 'NAME'

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    771
    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=
    Jul 13, 2007
  4. Ram  Prasad
    Replies:
    21
    Views:
    2,821
    Kenneth Brody
    Jul 31, 2007
  5. carl
    Replies:
    7
    Views:
    2,724
    Johannes Schaub (litb)
    Dec 6, 2009
Loading...

Share This Page