pass a pointer array to a function

M

Michael

HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
....

the above function worked but since i moved to Ubuntu i get libpng
error: Decompression error (not always but for most pngs)
Anyway following this:
http://www.gamedev.net/community/forums/topic.asp?topic_id=546917
I hope to fix that error by moving SDL_Surface out of this function
and pass the value as parameter?
So how to declare SDL_Surface and the LoadGLTexture function?
lotto is declared like: int lotto[5];
Many thanks
Michael
 
F

Francesco S. Carta

HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...

the above function worked but since i moved to Ubuntu i get libpng
error: Decompression error (not always but for most pngs)
Anyway following this:
http://www.gamedev.net/community/forums/topic.asp?topic_id=546917
I hope to fix that error by moving SDL_Surface out of this function
and pass the value as parameter?
So how to declare SDL_Surface and the LoadGLTexture function?
lotto is declared like: int lotto[5];

Your issue isn't about C++, it's about SDL, OpenGL and C - and as such
it's off topic here.

Once more, please read the FAQ and follow its guidelines before posting
your questions - if you really have a C++ related question.

That's not just an advice anymore, by now I think it's almost a requirement.
 
J

Joe Greer

HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...

T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

joe
 
J

Joe Greer

HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...

T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

joe

I should be clearer. An array declaration with a variable used as its size
is not legal in C++. They are called VLAs in C99 (which gcc also
supports). The C++ equivalent is a vector.

joe
 
F

Francesco S. Carta

No my question is exactly what the title says noting else

And my reply is exactly the one you snipped, pay particular attention to
FAQ5.8, if you happen to pass there: reading the FAQ could actually and
directly solve your issues - that is, your issue could be a specific FAQ.

Besides, you happened to get some help even missing to comply with those
guidelines - and missing to come back to your old threads, which are
still open, is just one further thing that is _not_ buying you further help.

I might be wrong, though. You may sit down waiting to be spoon-fed with
a solution to your problems without following the guidelines, and you
could eventually succeed - Usenet is fantastic in breaking this kind of
expectations - look, it just happened.
 
F

Francesco S. Carta

HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...

T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

joe

I should be clearer. An array declaration with a variable used as its size
is not legal in C++. They are called VLAs in C99 (which gcc also
supports). The C++ equivalent is a vector.

Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.
 
Ö

Öö Tiib

on 19/07/2010 16:32:42 said:
@news.hispeed.ch:
HI
int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...
T a[<variable>] isn't legal in C++, it's a C99 thing.  Use a vector
instead.
joe
I should be clearer.  An array declaration with a variable used as its size
is not legal in C++.  They are called VLAs in C99 (which gcc also
supports).  The C++ equivalent is a vector.

Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.

Nope. It should be compile time integral constant expression greater
than zero by existing standard.
 
F

Francesco S. Carta

on 19/07/2010 16:32:42 said:
@news.hispeed.ch:

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...
T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

I should be clearer. An array declaration with a variable used as its size
is not legal in C++. They are called VLAs in C99 (which gcc also
supports). The C++ equivalent is a vector.

Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.

Nope. It should be compile time integral constant expression greater
than zero by existing standard.

Ouch... it's really like that? My compiler accepted to create the array
within the function, with the const parameter... sorry for the wrong
addition.
 
F

Francesco S. Carta

on 19/07/2010 16:32:42 said:
@news.hispeed.ch:

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...
T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

I should be clearer. An array declaration with a variable used as its size
is not legal in C++. They are called VLAs in C99 (which gcc also
supports). The C++ equivalent is a vector.

Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.

Nope. It should be compile time integral constant expression greater
than zero by existing standard.

I've tried to look it up in the drafts I have underhand, but I only
found that it needs a constant-expression, it doesn't specify that it
needs to be a /compile time/ integral constant... was it already part of
C++98 or it has been introduced by C++03?

This is the part I found: [dcl.array] "If the constant-expression (5.19)
is present, it shall be an integral constant expression and its value
shall be greater than zero."
 
Ö

Öö Tiib

on 19/07/2010 12:17:52 said:
@news.hispeed.ch:
HI
int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...
T a[<variable>] isn't legal in C++, it's a C99 thing.  Use a vector
instead.
joe
I should be clearer.  An array declaration with a variable used as its size
is not legal in C++.  They are called VLAs in C99 (which gcc also
supports).  The C++ equivalent is a vector.
Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.
Nope. It should be compile time integral constant expression greater
than zero by existing standard.

I've tried to look it up in the drafts I have underhand, but I only
found that it needs a constant-expression, it doesn't specify that it
needs to be a /compile time/ integral constant... was it already part of
C++98 or it has been introduced by C++03?

This is the part I found: [dcl.array] "If the constant-expression (5.19)
is present, it shall be an integral constant expression and its value
shall be greater than zero."

Yep. So they name that compile time constant thing in standard.
Similar wording they use for case label.

[6.4.2/2]
Any statement within the switch statement can be labeled with one or
more case labels as follows:
case constant-expression :
where the constant-expression shall be an integral constant-
expression.

Try if your extended compiler lets to use const int function parameter
as case label. ;) Like Joe said VLA is C99 so compilers extend it
often, but strictly it is not by standard.
 
F

Francesco S. Carta

on 19/07/2010 12:17:52 said:
Joe Greer<[email protected]>, on 19/07/2010 16:32:42, wrote:
@news.hispeed.ch:

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...
T a[<variable>] isn't legal in C++, it's a C99 thing. Use a vector
instead.

I should be clearer. An array declaration with a variable used as its size
is not legal in C++. They are called VLAs in C99 (which gcc also
supports). The C++ equivalent is a vector.
Although I completely agree with you that using a vector instead of an
array is the way to go, I want to point out that adding the const
keyword to that int parameter would suffice to allow that array
declaration within the function.
Nope. It should be compile time integral constant expression greater
than zero by existing standard.

I've tried to look it up in the drafts I have underhand, but I only
found that it needs a constant-expression, it doesn't specify that it
needs to be a /compile time/ integral constant... was it already part of
C++98 or it has been introduced by C++03?

This is the part I found: [dcl.array] "If the constant-expression (5.19)
is present, it shall be an integral constant expression and its value
shall be greater than zero."

Yep. So they name that compile time constant thing in standard.
Similar wording they use for case label.

[6.4.2/2]
Any statement within the switch statement can be labeled with one or
more case labels as follows:
case constant-expression :
where the constant-expression shall be an integral constant-
expression.

Try if your extended compiler lets to use const int function parameter
as case label. ;) Like Joe said VLA is C99 so compilers extend it
often, but strictly it is not by standard.

Uhm, maybe that distinction between "constant expression" and "compile
time constant expression" should be made explicit somewhere - and maybe
it already is.

Thank you very much for all the additional details - well, then that's
truly a further reason to use std::vector instead of arrays ;-)
 
P

Paul Bibbings

Michael said:
HI

int LoadGLTexture(char *pFileName, int TextureId)
{
SDL_Surface* lotto[TextureId]
lotto[TextureId] = IMG_Load(TextureFileName)
...

lotto is declared like: int lotto[5];

Does this make sense to you? I'd wondered if you were getting something
a little confused from the sparse information you'd given in an earier
post. To translate:

lotto is declared like:
SDL_Surface* lotto[TextureId];

lotto is declared like:
int lotto[5];

So, which is it? Any surprise that you get:
invalid conversion from ¡®SDL_Surface*¡¯ to ¡®int¡¯
?

Regards

Paul Bibbings
 

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,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top