Create readonly array of data?

S

Susan Rice

I want to create a readonly array of data, then a readonly array of a
structure. This is data I access but I want it protected against
accidental change. The following is my test code.

#include "stdafx.h"

struct LVC
{
unsigned short int lo;
unsigned short int hi;
};

void main()
{
//This seems to work
static const unsigned short int LV[4] =
{0xAC00,
0xAC1C,
0xAC38,
0xAC54 };

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
{ 0xAC01, 0xAC1B },
{ 0xAC1D, 0xAC37 },
{ 0xAC39, 0xAC53 },
{ 0xAC55, 0xAC6F },
};

unsigned short i,j;

i = LVC[2].lo;
j = LVC[2].hi;
}

I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)
 
J

jacob navia

Susan Rice a écrit :
//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
static const struct LVC is the type. You have to give a *name*
to that array.

for instance
static const struct LVC MyTable[4] = {
etc

Then you use THAT name:
i = MyTable[2].lo;
j = MyTable[2].hi;

jacob

P.S.
it is not void main() but int main(void).
But that is a detail.
 
D

Default User

Susan said:
I want to create a readonly array of data, then a readonly array of a
structure. This is data I access but I want it protected against
accidental change. The following is my test code.

#include "stdafx.h"

See below about this.
struct LVC

It's generally prefered by most to reserve all caps for macros.
{
unsigned short int lo;
unsigned short int hi;
};

void main()

This should be int main(void)
{
//This seems to work
static const unsigned short int LV[4] =
{0xAC00,
0xAC1C,
0xAC38,
0xAC54 };

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {

LVC is the name of struct type that you created above. What you wanted
was something like:

static const struct LVC LVC_array[4] = {
{ 0xAC01, 0xAC1B },
{ 0xAC1D, 0xAC37 },
{ 0xAC39, 0xAC53 },
{ 0xAC55, 0xAC6F },
};

unsigned short i,j;

i = LVC[2].lo;
j = LVC[2].hi;

Then change these two names as well.
}

I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)

This has to do with pre-compiled headers in VC++. I don't know
specifically to correct that in Express, but check your project
settings to remove any dependence. If you can't figure it out, you'll
need a Microsoft newsgroup.




Brian
 
R

rhle.freak

I'm using Microsoft Visual C++ Express Edition
(I'd also like to get rid of that #include "stdafx.h" if
there's some compiler configuration that will allow me
to do that.)

when u create your project in msvc++

new project->Win32(win32 console app template is automatically
selected) ->
(enter a name for the project)->next->select "empty project"
option->finish

then add the header and source files that u need.

and more simply...
new project->select "general " option from the Project type window
->finish

//THIS DOESN'T WORK. COMPILER COMPLAINS
static const struct LVC[4] = {
{ 0xAC01, 0xAC1B },
u did not name the "template" ..it has been answered above

regards
 
C

CBFalconer

rhle.freak said:
when u create your project in msvc++

U never posted in this thread. I don't believe he even uses
c.l.c. If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.
 
R

Richard Heathfield

CBFalconer said:
U never posted in this thread. I don't believe he even uses
c.l.c.

I believe he has done so (although I admit it may have been cp rather than
clc) - a month or so ago.

If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.

Will you not take pity on someone who appears to be trying to coax his
Microsoft implementation into conforming mode?
 
K

Keith Thompson

rhle.freak said:
when u create your project in msvc++ [...]
then add the header and source files that u need. [...]
u did not name the "template" ..it has been answered above

Please don't use silly abbreviations like "u" for "you". It makes
your articles harder to read, and a lot of people just won't bother.

And please don't snip attribution lines (lines of the form
"So-and-so writes:").
 
R

rhle.freak

c.l.c. If you refrained from snipping attributions it would be
easier to follow this. In addition msvc++ is system specific and
off-topic here.

--

please do check the earlier thread "stack" which i had posted a few
days ago! ! regarding using msvc++ ,yes its a specific problem and off
topic but there is no harm if i am using the same compiler n can help
someone with something really simple and please do forgive me because
i am new to using Usenet
(Google groups to be specific) and my format of posting was wrong,i
will definitely try to improve on that!!
 
C

CBFalconer

rhle.freak said:
please do check the earlier thread "stack" which i had posted a few
days ago! ! regarding using msvc++ ,yes its a specific problem and off
topic but there is no harm if i am using the same compiler n can help
someone with something really simple and please do forgive me because
i am new to using Usenet
(Google groups to be specific) and my format of posting was wrong,i
will definitely try to improve on that!!

'Another thread' has nothing to do with it. Articles need to stand
alone. That is the point of quoting relevant matter. You would be
well advised to get a proper newsreader and access usenet directly
instead of through the flawed google interface. Also never use
silly geekspeak, such as 'u' and 'n' abbreviations. They only
serve to annoy and make reading hard, especially for non-English
speakers.

Just delete the #include <stdafx.h> and #include the appropriate
standard C includes. The C-library link below will be useful, as
will the C99 standard.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net> (C-info)

Some informative links about posting:
<http://members.fortunecity.com/nnqweb/> (newusers)
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/> (taming google)
 
F

Frodo Baggins

alone. That is the point of quoting relevant matter. You would be
well advised to get a proper newsreader and access usenet directly
instead of through the flawed google interface. Also never use

<snip>

How do I access usenet directly?
For free ?

Regards,
Frodo B
 
C

CBFalconer

Frodo said:
CBFalconer wrote:



<snip>

How do I access usenet directly? For free ?

Your ISP should provide that. Ask them, and they will also tell
you what the servers URL is. This is to be accessed by a news
reader, not a browser. If they don't provide a server they are not
a proper ISP, but you have the recourse of various free
newservers. Others exist, and people may chime in with their URLs.

Some free news servers
<http://www.teranew.com> (free)
<http://www.newsfeeds.com/signup.htm> (pay)
 
N

Nelu

CBFalconer said:
Your ISP should provide that. Ask them, and they will also tell
you what the servers URL is. This is to be accessed by a news
reader, not a browser. If they don't provide a server they are not
a proper ISP, but you have the recourse of various free
newservers. Others exist, and people may chime in with their URLs.

Some free news servers
<http://www.teranew.com> (free)
<http://www.newsfeeds.com/signup.htm> (pay)

http://news.aioe.org
 
R

Randy Howard

<snip>

How do I access usenet directly?

It depends upon your ISP generally.
For free ?

That depends upon how you define free(). :)

If your ISP bundles it into the price of your normal access fees, you
might consider it to be free in that context, as I do.

You'll probably need to look on the ISP's website support page (if any)
for things like "News server", or "NNTP".

It's usually something like:

news.ispdomainname.com

And may or may not require a user id and password for authentication.

As for suitable newsreaders, that depends upon your operating system.
Some examples of newsreaders are:

Windows: Gravity, SuperGravity, Agent, Thunderbird, Outlook Express
OS X: Hogwasher, MTNewswatcher, Thunderbird
Linux: A ton of them, including Thunderbird, slrn, trn, nn, xrn, and
many more.

In all almost all cases, the interface provided to Usenet is vastly
superior to that of Google.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top