I have a program that uses a large lookup table, provided as a large
array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.
The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Thoughts?
Jul 6 '07
17 1740
On Jul 6, 3:51 pm, Francine.Ne...@ googlemail.com wrote:
I have a program that uses a large lookup table, provided as a
large array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
1) #including a .c file is weird.
Not really, that would be my preferred solution here.
Also, you could help the compiler out by declaring
the array as const (assuming it is in fact meant
to not change).
Old Wolf wrote:
>
On Jul 6, 3:51 pm, Francine.Ne...@ googlemail.com wrote:
I have a program that uses a large lookup table, provided as a
large array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
1) #including a .c file is weird.
Not really, that would be my preferred solution here.
Also, you could help the compiler out by declaring
the array as const (assuming it is in fact meant
to not change).
I would remove the static,
and declare the array as extern in a.h,
and include "a.h" in main.c
and have int bigtbl in a.c.
--
pete
On Jul 9, 9:49 pm, pete <pfil...@mindsp ring.comwrote:
I would remove the static,
and declare the array as extern in a.h,
and include "a.h" in main.c
and have int bigtbl in a.c.
I like encapsulation -- if a data table is
only meant to be used in one place, then I
like it to be only visible in that one place,
and not externally visible. Fr************@ googlemail.com skrev:
I have a program that uses a large lookup table, provided as a large
array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.
The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Thoughts?
You could also read the data from a file.
August
You could take the table and put it in another c "table.c" file which
will be among the list of files that are compiled and linked. its
associated "table.h" will contain extern of the table which can be
included in other modules and used. What say?
On Jul 11, 6:17 pm, Manish Tomar <manish.to...@g mail.comwrote:
You could take the table...
Please quote context. I wrote:
I have a program that uses a large lookup table, provided as a large
array in the source:
static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };
Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I'd like to put it in a separate file and
#include that.
The style question is: should the separate file have a .c or .h
extension?
On Jul 11, 6:17 pm, Manish Tomar <manish.to...@g mail.comwrote:
You could take the table and put it in another c "table.c" file which
will be among the list of files that are compiled and linked.
Say yes - this is what I did, and with hindsight it seems fine to me.
its
associated "table.h" will contain extern of the table which can be
included in other modules and used. What say?
Say no way - violates encapsulation. (Did you miss the static?)
On Thu, 12 Jul 2007 02:59:39 -0000, Fr************@ googlemail.com
wrote:
>On Jul 11, 6:17 pm, Manish Tomar <manish.to...@g mail.comwrote:
>You could take the table...
Please quote context. I wrote:
>I have a program that uses a large lookup table, provided as a large array in the source:
static int bigtbl[]={123, 456, /* etc. etc. */ 9999 };
Now this table is pretty big, and having it clutter up my main source file is quite ugly. So I'd like to put it in a separate file and #include that.
The style question is: should the separate file have a .c or .h extension?
On Jul 11, 6:17 pm, Manish Tomar <manish.to...@g mail.comwrote:
>You could take the table and put it in another c "table.c" file which will be among the list of files that are compiled and linked.
Say yes - this is what I did, and with hindsight it seems fine to me.
>its associated "table.h" will contain extern of the table which can be included in other modules and used. What say?
Say no way - violates encapsulation. (Did you miss the static?)
If you're after encapsulation, then the access functions for the table
go in the same .c file, and the .h file contains their prototypes.
Including the table in files that use it doesn't provide any
encapsulation.
--
Al Balmer
Sun City, AZ
On Jul 12, 12:40 pm, Al Balmer <albal...@att.n etwrote:
[...]
>
Including the table in files that use it doesn't provide any
encapsulation.
However, defining the table static in the one and only file that uses
it does provide data hiding. Which is often conflated with
encapsulation.
Regards,
-=Dave This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):
class C(object): pass
C.__bases__ = bases
dict = 0
|
by: Mark |
last post by:
Hi - I want to allow users of an intranet application, to select their
own colours etc.
So I have a tbale in my database, which has fields called bgcolour,
fontcolour etc. As I want all pages to get the users colours, I have an
includes file at the top of each page:
<!--#include file="userconfig.asp" -->
This is:
|
by: wired |
last post by:
Hi,
I've just taught myself C++, so I haven't learnt much about style or
the like from any single source, and I'm quite styleless as a result.
But at the same time, I really want nice code and I go to great
lengths to restructure my code just to look concise and make it more
manageable.
When I say this, I'm also referring to the way I write my functions.
It seems to me sometimes that I shouldn't have many void functions
accepting...
|
by: Dave Moore |
last post by:
I realize this is a somewhat platform specific question, but I think it is
still of general enough interest to ask it here ... if I am wrong I guess I
will find out 8*).
As we all know, DOS uses two characters (carriage-return and line-feed), to
signal the end of a line, while UNIX uses only one (line-feed). When using
getline in C++, one can only specify a single character as the terminator
(default is '\n'), so if you read a line of...
|
by: Exits Funnel |
last post by:
Hello,
I'm a little confused about where I should include header files and was
wondering whether there was some convention. Imagine I've written a
class foo and put the definition in foo.h and the implementation of its
member functions in foo.cpp (which obviously #inludes foo.h) and further
assume that it depends on a class bar which is defined in bar.h.
It seems that there are the following two scenarios:
| |
by: lawrence |
last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this
script hoping to animate some div blocks on a page. You can see the
page here: http://www.keymedia.biz/demo.htm
Can anyone tell me why these DIVs don't drift to the left as they are
supposed to?
<script language="javascript">
|
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does nothing in IE.
I'd be greatful for any assistance. Also, if I will have problems the
code on Opera or Safari, I'd appreciate any pointers--I don't have a
Mac to test Safari.
THanks very much,
Michael
|
by: amerar |
last post by:
Hi All,
I can make a page using a style sheet, no problem there. However, if I
make an email and send it out to my list, Yahoo & Hotmail totally
ignore the style tags. It looks fine in Netscape though.....
Question: I've tried linking & embedding the style tags with no luck.
How can I use them inline? I've read that inline style sheets is the
way to go if you want them to work in most email clients.......
|
by: jarek |
last post by:
Hi,
this is my code:
CSSStyleDeclaration.prototype.__defineSetter__('display',
displaySetter);
function displaySetter(value) {
var parent = findParent(document, this);
if (parent) {
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |