473,322 Members | 1,778 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,322 software developers and data experts.

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 #1
17 1701

Maybe you can put it in a special named file such as *bigtbl.data*.

Fr************@googlemail.com writes:
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?
Best regards
Xu Weijiang
--
everything has its rules!
Jul 6 '07 #2

<Fr************@googlemail.comwrote in message
news:11**********************@d30g2000prg.googlegr oups.com...
>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.
Some might call it weird, others not. But it's perfectly
valid. I'd use either .c or some other extension which
indicates what it is, perhaps .tbl
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Same remarks about 'weird' as above. In a file (whatever its
name) intended to be #included by more than one other file
(the traditional meaning of a 'header file), it would not be
a good idea.

I've also seen the following form in third party libraries I've used:
/* ext.h */
#define EXTERN extern
/* array.h */
EXTERN int array[SIZE];
/* array.c */
#define EXTERN
#include "array.h" /* 'EXTERN' resolves to nothing, so definition occurs */
/* otherfiles.c */
#include ext.h
#include array.h /* causes extern declaration */
I don't really care for that way, I'd probably use
something like a .tbl file

-Mike
Jul 6 '07 #3
Fr************@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 };

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?
No, including a .c file is NOT weird. Being a .c file, you are
warned not to #include it in multiple sources (as you normally can
a .h file). You could also make it a .d or .dat etc. file if you
wish.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 6 '07 #4

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 };

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?
Can you share the logic/Algo which you are runnig on your lookup
table,
Just wanted to know as I also have such a big lookup table, and
my major concern about it is that I need to reduce the search time.
(Optimising)

Can others also help and provide there thoughts.

Thanks
Ranjeet Gupta

Jul 6 '07 #5
On 6 Jul, 04:51, 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 };

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.
I agree strongly.
2) putting a definition, rather than just declarations, in a .h file
is also weird.
Also agreed. You can conform to both of these by using
the linker...

$ for i in data.h data.c foo.c; do echo "***** $i *****"; cat $i; done
***** data.h *****

#define TBL_SIZE 3
extern int bigtbl[ TBL_SIZE ];
***** data.c *****
#include "data.h"

int bigtbl[ TBL_SIZE ] = { 0, 1, 2};
***** foo.c *****

#include <stdio.h>
#include "data.h"

int
main(void)
{
printf( "Last entry:%d\n", bigtbl[ TBL_SIZE - 1 ]);
return 0;
}
$ gcc -c data.c
$ gcc -c foo.c
$ gcc -o foo foo.o data.o
$ ./foo
Last entry:2

Jul 6 '07 #6
On Jul 5, 10: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 };

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?
When I've done this sort of thing in the past, the #included file was
generated automatically, and did not contain the declaration itself.
It also had the extension ".data". So I'd do something like this in
main.c:

#include <stdio.h /* or whatever you need */

static int bigtbl[] = {
#include "bigtbl.data"
};

/* etc. */

HTH,

-=Dave

Jul 6 '07 #7
On Jul 6, 5:23 pm, Dave Hansen <i...@hotmail.comwrote:
On Jul 5, 10: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 };
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?

When I've done this sort of thing in the past, the #included file was
generated automatically, and did not contain the declaration itself.
It also had the extension ".data". So I'd do something like this in
main.c:

#include <stdio.h /* or whatever you need */

static int bigtbl[] = {
#include "bigtbl.data"
};

/* etc. */

HTH,

-=Dave- Hide quoted text -

- Show quoted text -
Hi
How was "bigtb.data" structured ?
Since you have already used curly brackets , is it only values
seperated with commas ?

Jul 6 '07 #8
On Fri, 06 Jul 2007 04:24:34 GMT, "Mike Wahler" wrote:
><Fr************@googlemail.comwrote:
>1) #including a .c file is weird.

Some might call it weird, others not. But it's perfectly
valid. I'd use either .c or some other extension which
indicates what it is, perhaps .tbl
Microsoft uses .inl (probably means 'inline').
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jul 6 '07 #9
On Jul 6, 11:48 am, tguclu <tugrul.gu...@gmail.comwrote:
On Jul 6, 5:23 pm, Dave Hansen <i...@hotmail.comwrote:
[...]
static int bigtbl[] = {
#include "bigtbl.data"
};
[...]
>
Hi
How was "bigtb.data" structured ?
Since you have already used curly brackets , is it only values
seperated with commas ?
Exactly. It made the application that generated bigtbl.data a little
easier to write as well.

Regards,

-=Dave

Jul 6 '07 #10
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...@mindspring.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...@gmail.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...@gmail.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...@gmail.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...@gmail.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.netwrote:
[...]
>
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
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={}):...
2
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...
35
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...
8
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...
18
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...
15
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...
21
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...
33
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...
4
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.