Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help, I'm exceeding 2048 char length

1 view
Skip to first unread message

jt

unread,
Jul 2, 2002, 12:11:38 PM7/2/02
to
Trying to write a generic "C" function to run both in Unix as well as Win32
console.

The problem is I have a continous string both ascii and binary characters,
which is PCL bytes(prn file) that is about 22K long.

I can not have it as a file to load, it must be put into the code and
printed from there.

I tried char pcl[]="\x28,\x34,\x44,\x1b, .... "; and so on to 22K chars, and
other different ways with no answer to satisfy the compiler.

Looking for advice or any tricks to having some array or whatever can be
done to have inside the code rather loading it from a file. Note: has to be
generic to compile in Unix and Win32 console as well.

I really appreciate any adivse you can give me.

Thank you,
jt

Ben Pfaff

unread,
Jul 2, 2002, 12:18:38 PM7/2/02
to
"jt" <jts...@hotmail.com> writes:

> I tried char pcl[]="\x28,\x34,\x44,\x1b, .... "; and so on to 22K chars, and
> other different ways with no answer to satisfy the compiler.

Leave out the commas. Alternatively, express it as
char pcl[] = {0x28,0x34,0x44,0x1b, ...and so on...};
You might want to use unsigned char instead of char, by the way,
since you seem to want to deal with unsigned values.

> Looking for advice or any tricks to having some array or whatever can be
> done to have inside the code rather loading it from a file. Note: has to be
> generic to compile in Unix and Win32 console as well.

I don't know why you think this would be OS-specific. It's just
a bunch of binary data, and that's sufficiently supported by the
language, so that there is no need to use implementation-specific
features.

istartedi

unread,
Jul 2, 2002, 3:33:05 PM7/2/02
to

jt <jts...@hotmail.com> wrote in message
news:_gkU8.113780$0g1.2...@twister.tampabay.rr.com...

> Trying to write a generic "C" function to run both in Unix as well as
Win32
> console.
>
> The problem is I have a continous string both ascii and binary characters,
> which is PCL bytes(prn file) that is about 22K long.

Some early MS compilers would choke if a single object was, IIRC, greater
than 64k. If you have code lumped into the text, maybe that's happening.
Try isolating the string in one file. Of course, you can also break the
string into several string. Iin fact, if you are going to printf this
string you need to check what the limits are on what printf is required to
accept. No time to look that up now. I'm sure somebody can cite the
spec... you didn't specify which version of the C standard

--$teve
comm...@vrml3d.com

Robert Wessel

unread,
Jul 2, 2002, 7:38:42 PM7/2/02
to
"jt" <jts...@hotmail.com> wrote in message news:<_gkU8.113780$0g1.2...@twister.tampabay.rr.com>...

I don't know which compilers you're using, but you may be running into
one of two limits: A conforming compiler need support no more than
509 characters in a line, or the same limit in a string.

If you're hitting the lime length limit for your compiler, using
string concatenation may get you past your problem:

char a[] = "abc"
"def"
"ghi"
"jkl"
"mno";

In any event, even if that works, it's not strictly conforming C
(since you'll end up concatenating a string longer than 509
characters), and you may well find compilers that don't like that
large a string. FWIW, a quick test shows MSVC5 choking somewhere
between 32700 and 32800 characters in a string (and I'll bet the limit
is close to 32767).

Also, watch out if your 22KB string grows. The minimum limit for an
object is 32767 bytes.

Ben's suggestion to use the array initialization form is probably your
best bet.

Dan Pop

unread,
Jul 3, 2002, 8:41:36 AM7/3/02
to
In <_gkU8.113780$0g1.2...@twister.tampabay.rr.com> "jt" <jts...@hotmail.com> writes:

>Trying to write a generic "C" function to run both in Unix as well as Win32
>console.
>
>The problem is I have a continous string both ascii and binary characters,
>which is PCL bytes(prn file) that is about 22K long.
>
>I can not have it as a file to load, it must be put into the code and
>printed from there.
>
>I tried char pcl[]="\x28,\x34,\x44,\x1b, .... "; and so on to 22K chars, and

Are you *sure* you need those commas inside the string literal?

>other different ways with no answer to satisfy the compiler.

If the compiler is complaining about a string literal that is too long,
initialise pcl using the array initialiser syntax:

static unsigned char pcl[] = {0x28, 0x34, 0x44, 0x1b, ... };

The initialiser list can be continued on a new line after any value,
if it's the line length that upsets the compiler.

If the compiler still complains, get a better compiler.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan...@ifh.de

Graham Whiteside

unread,
Jul 3, 2002, 6:36:41 PM7/3/02
to
Here's a possible solution, I have used it several times in my own programs
but you will need to
do a bit of work to implement it.

Here's the principle......
Your program reads the data in directly from the pcl file the first time it
executes after compilation.
It then saves itself (or at least part of itself) so the next time it runs
the pcl info is embedded.

This is what you need to do......
Declare a variable big enough to hold the data, give it a value that you can
search for in the exe file
This variable needs to be global & declare it before any other variables.

ie.
char pcl[3000]="Empty PCL data";

When the program first runs test if this marker is present.
ie
if(strcmp(pcl,"Empty PCL data")==0){....

Now open your pcl source file and read it into the pcl array, close the
file.

Now open the exe file for read/write binary, search your compiled exe file
for the same phrase.
rewind the file pointer to the start of the phrase then write the whole
array to the exe file.

And that's it. the next time it runs the ""Empty PCL** test will fail and
provided your
array was written correctly it will now contain the embedded pcl info your
program needs.

Graham Whiteside.


"jt" <jts...@hotmail.com> wrote in message
news:_gkU8.113780$0g1.2...@twister.tampabay.rr.com...

jt

unread,
Jul 3, 2002, 7:48:51 PM7/3/02
to

"Dan Pop" <Dan...@ifh.de> wrote in message
news:afure0$mc8$1...@sunnews.cern.ch...

Yep, that did the trick using hex instead

Thanks to all that helped
jt

E. Gibbons

unread,
Jul 5, 2002, 3:06:33 PM7/5/02
to
In article <_gkU8.113780$0g1.2...@twister.tampabay.rr.com>,

Other people suggested using the array-style initializer instead of
the string-literal-style, and sounds like that was all you needed.
If that wasn't enough to get your compiler to do what you need, though,
the next suggestion would be to break up the object in question into
an array of smaller strings:

unsigned char * pcl_array[] = {
"\x28\x34\x44\x1b",
"\x28\x34\x44\x1b",
"\x28\x34\x44\x1b",
"\x28\x34\x44\x1b",
};

Make each string small enough that the compiler will accept it (say,
256 chars, or perhaps just what will fit comfortably across the screen
in under 80 source chars), then re-write your functions that access this
data, to handle an array instead of a single string.

Also, as someone else pointed out, you should probably be using unsigned
char for this, from the looks of it.

Since you were originally using the string-literal initializer, I assume
that you have some reason to know that '\0' chars will not appear in
your data?

--Ben

--

0 new messages