473,805 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Style question: #include

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).

Jul 8 '07 #11
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
Jul 9 '07 #12
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.

Jul 9 '07 #13
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
Jul 10 '07 #14
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?

Jul 11 '07 #15
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?)

Jul 12 '07 #16
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
Jul 12 '07 #17
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

Jul 12 '07 #18

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

Similar topics

12
3837
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
2
2017
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:
35
4565
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...
8
3446
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...
18
2261
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:
15
3251
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">
21
4007
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
33
2510
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.......
4
2237
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) {
0
9596
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,...
0
10360
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 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...
1
7646
isladogs
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...
0
6876
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();...
0
5542
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...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
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
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
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...

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.