473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

const array

here is my data structure

typedef struct{
char colorType;
unsigned short numEntries;
unsigned int* palette;
}CLUT;

const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
//...
};

const CLUT clut001 = {RGBA555, 256, clut001palette};
const CLUT clutList[] = {
clut001,
};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?

thanks a lot

Jul 30 '07 #1
12 2218
just brainstorming think that I can code like this

const CLUT* clutList[] = {
&clut001, &clut002
};

Any other better approach?

On 7 30 , 3 44 , jackymaill...@gmail.com wrote:
here is my data structure

typedef struct{
char colorType;
unsigned short numEntries;
unsigned int* palette;

}CLUT;

const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
//...

};

const CLUT clut001 = {RGBA555, 256, clut001palette};

const CLUT clutList[] = {
clut001,

};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?

thanks a lot

Jul 30 '07 #2
ja***********@gmail.com wrote:
here is my data structure

typedef struct{
char colorType;
unsigned short numEntries;
unsigned int* palette;
}CLUT;

const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
//...
};

const CLUT clut001 = {RGBA555, 256, clut001palette};
const CLUT clutList[] = {
clut001,
};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?
What is the compile error?

Post a complete, minimal program with all the errors.


Brian

Jul 30 '07 #3
It point to my last array
const CLUT clutList[] = {
clut001,

};
and said
"initializer is not a constant"
On 7 30 , 4 29 , "Default User" <defaultuse...@yahoo.comwrote:
jackymaill...@gmail.com wrote:
here is my data structure
typedef struct{
char colorType;
unsigned short numEntries;
unsigned int* palette;
}CLUT;
const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
//...
};
const CLUT clut001 = {RGBA555, 256, clut001palette};
const CLUT clutList[] = {
clut001,
};
however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?

What is the compile error?

Post a complete, minimal program with all the errors.

Brian

Jul 30 '07 #4
ja***********@gmail.com wrote:
>
const CLUT clut001 = {RGBA555, 256, clut001palette};

const CLUT clutList[] = {
clut001,
};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?
In C a const CLUT isn't a compile time constant. One of the things I
was surprised C99 didn't fix.

--
Ian Collins.
Jul 30 '07 #5
Ian Collins <ia******@hotmail.comwrites:
ja***********@gmail.com wrote:
>const CLUT clut001 = {RGBA555, 256, clut001palette};

const CLUT clutList[] = {
clut001,
};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?
In C a const CLUT isn't a compile time constant. One of the things I
was surprised C99 didn't fix.
The value of a const object sometimes *can't* be a compile-time constant:

const int const_but_not_constant = rand();

But yes, the language could have defined some *const* objects to be
compile-time constants, depending on how they're initialized.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 30 '07 #6
Keith Thompson wrote:
Ian Collins <ia******@hotmail.comwrites:
>ja***********@gmail.com wrote:
>>const CLUT clut001 = {RGBA555, 256, clut001palette};

const CLUT clutList[] = {
clut001,
};

however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?
In C a const CLUT isn't a compile time constant. One of the things I
was surprised C99 didn't fix.

The value of a const object sometimes *can't* be a compile-time constant:

const int const_but_not_constant = rand();

But yes, the language could have defined some *const* objects to be
compile-time constants, depending on how they're initialized.
Following the C++ rules would have been a sensible option, they
certainly lead to cleaner code and fewer ugly macros or the kludgey enum
hack.

--
Ian Collins.
Jul 30 '07 #7
On Mon, 30 Jul 2007 00:54:29 -0700, ja***********@gmail.com wrote:
>just brainstorming think that I can code like this
Please don't top post.
>const CLUT* clutList[] = {
&clut001, &clut002
};
How long would it have taken to generate a small function to compile
so you could see the errors before posting?

clutList is an array of two pointers to CLUT. Each element of the
array must contain a value of type CLUT*. clut001 is an array of 16
int. &clut001 has type pointer to array of 16 int, that is
int(*)[16]. The two are not related and the attempting to initialize
the former with the latter is a constraint violation requiring a
diagnostic.
>
Any other better approach?

On 7 30 , 3 44 , jackymaill...@gmail.com wrote:
>here is my data structure

typedef struct{
char colorType;
unsigned short numEntries;
unsigned int* palette;

}CLUT;

const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
//...

Remove del for email
Jul 31 '07 #8
ja***********@gmail.com wrote:
here is my data structure
[replacement with comments below]
however, it lead to an compile error, anyhope that I can use a
variable to store my CLUT attribute then assign it to an array?
#define RGBA555 127 /* mha: some definition is needed for
compilation. Make sure that
whatever this value is that it is in
the range of a signed char, else
change colorType in your struct to
be unsigned char, or else be sure
that RGBA555 >= 0 or that colorType
is an unsigned char. */
typedef struct
{
char colorType;
unsigned short numEntries;
const unsigned int *palette; /* mha: added 'const' to avoid
discarding constness. */
} CLUT;

const unsigned int clut001palette[16] = {
0x8000F000, 0x0000E000, 0x0000C800, 0x0000C000,
0x00009800, 0x00009800, 0x00009800, 0x00048004,
0x00006C00, 0x00006400, 0x0008500C, 0x00106810,
0x00108C10, 0x00149814, 0x0018A818, 0x0018A018,
};

const CLUT clut001 = { RGBA555, 256, clut001palette };


int main(void)
{
const CLUT clutList[] = { clut001, }; /* mha: This cannot have
file scope, since the
initializer is not
constant. If you think
it is, check the FAQ. */

return 0;
}
Jul 31 '07 #9
Barry Schwarz wrote:
On Mon, 30 Jul 2007 00:54:29 -0700, ja***********@gmail.com wrote:
>just brainstorming think that I can code like this

Please don't top post.
>const CLUT* clutList[] = {
&clut001, &clut002
};

How long would it have taken to generate a small function to compile
so you could see the errors before posting?

clutList is an array of two pointers to CLUT. Each element of the
array must contain a value of type CLUT*. clut001 is an array of 16
int.
No, it isn't. Read the OP again:

const CLUT clut001 = {RGBA555, 256, clut001palette};

--
Ian Collins.
Jul 31 '07 #10
On Tue, 31 Jul 2007 12:43:26 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Barry Schwarz wrote:
>On Mon, 30 Jul 2007 00:54:29 -0700, ja***********@gmail.com wrote:
>>just brainstorming think that I can code like this

Please don't top post.
>>const CLUT* clutList[] = {
&clut001, &clut002
};

How long would it have taken to generate a small function to compile
so you could see the errors before posting?

clutList is an array of two pointers to CLUT. Each element of the
array must contain a value of type CLUT*. clut001 is an array of 16
int.

No, it isn't. Read the OP again:

const CLUT clut001 = {RGBA555, 256, clut001palette};
By george, you're right. I wonder where the palette went.
Remove del for email
Jul 31 '07 #11
On Tue, 31 Jul 2007 10:32:01 +1200, Ian Collins <ia******@hotmail.com>
wrote:
Keith Thompson wrote:
Ian Collins <ia******@hotmail.comwrites:
<snip example>
In C a const CLUT isn't a compile time constant. One of the things I
was surprised C99 didn't fix.
The value of a const object sometimes *can't* be a compile-time constant:

const int const_but_not_constant = rand();

But yes, the language could have defined some *const* objects to be
compile-time constants, depending on how they're initialized.
Following the C++ rules would have been a sensible option, they
certainly lead to cleaner code and fewer ugly macros or the kludgey enum
hack.
Although it wouldn't have helped in this example, since the C++ rules
only apply to scalar integer and enumeration types (which are distinct
in C++ but in C enumeration types _are_ integer types).

- formerly david.thompson1 || achar(64) || worldnet.att.net
Aug 26 '07 #12
David Thompson wrote:
On Tue, 31 Jul 2007 10:32:01 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Keith Thompson wrote:
>>Ian Collins <ia******@hotmail.comwrites:
<snip example>
>>>In C a const CLUT isn't a compile time constant. One of the things I
was surprised C99 didn't fix.
The value of a const object sometimes *can't* be a compile-time constant:

const int const_but_not_constant = rand();

But yes, the language could have defined some *const* objects to be
compile-time constants, depending on how they're initialized.
Following the C++ rules would have been a sensible option, they
certainly lead to cleaner code and fewer ugly macros or the kludgey enum
hack.

Although it wouldn't have helped in this example, since the C++ rules
only apply to scalar integer and enumeration types (which are distinct
in C++ but in C enumeration types _are_ integer types).
But it would have helped the OP.

--
Ian Collins.
Aug 26 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
4
by: cppsks | last post by:
I have been working on making a constant array available for the clients. However, it is placing it in the text segment, and external references result in unresolved references to the array. Taking...
6
by: Dylan Nicholson | last post by:
Is there any way of declaring the parameter "array" below to be const, so that the function as written will not compile: void foo(int array /*const*/) { array = array; // should not be allowed...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
16
by: herbertF | last post by:
Hi guys, In a program (not my own) I encountered the declaration of a constant pointer to an array consisting of two other const pointers to arrays. Not quite sure why they do it so complicated,...
11
by: x-pander | last post by:
given the code: <file: c.c> typedef int quad_t; void w0(int *r, const quad_t *p) { *r = (*p); }
8
by: Roger Leigh | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 A lot of functions use const pointer arguments. If I have a non-const pointer, it is transparently made const when I pass it to the function, e.g....
12
by: hweekuan | last post by:
hi, it seems i can't assign the const variable u in class A, one way to solve the problem may be to build a copy constructor. however, why does C++ or vector class not like this code? my g++ is:...
10
by: Stephen Howe | last post by:
Hi Just going over some grey areas in my knowledge in C++: 1) If I have const int SomeConst = 1; in a header file, it is global, and it is included in multiple translations units, but it...
17
by: Andrea Taverna (Tavs) | last post by:
Subject: Initialization of a const matrix implemented as pointer-to-pointer Hello everyone. I've got the following matrix definition in a source file static const char **a; I need it to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.