C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

function pointer
Goto page Previous  1, 2, 3, 4 ... 11, 12, 13  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated)
View previous topic :: View next topic  
Author Message
those who know me have no
Guest





PostPosted: Mon Jan 30, 2006 6:02 pm    Post subject: Re: Globals. Reply with quote



in comp.lang.c.moderated i read:

Quote:
does the standard aywhere state that global variables will be initialsed
with 0 if not explicitly initialised?

yes.

--
a signature
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Barry Schwarz
Guest





PostPosted: Sat Feb 11, 2006 11:06 pm    Post subject: Re: Globals. Reply with quote



On 25 Jan 2006 11:13:23 GMT, Jasen Betts <jasen (AT) free (DOT) net.nz> wrote:

Quote:
does the standard aywhere state that global variables will be initialsed
with 0 if not explicitly initialised?

Yes, but the correct form of 0. Integers get 0, floating points get
0.0, and pointers get NULL. Not all of these are guaranteed to be all
bits zero.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Brian Inglis
Guest





PostPosted: Tue May 23, 2006 12:22 am    Post subject: Re: Some questions, big numbers library Reply with quote



On 11 May 2006 05:12:39 GMT in comp.lang.c.moderated,
pkochanek (AT) gmail (DOT) com wrote:

Quote:
Hi,

I've to implement fast library for big numbers arithmetics. I'll store
the number in the table of unsigned long variables. And now i've a
question: what will be faster:

a) storing in one cell of the table values from 0 to 999999999
so for example number 1111222233334444 will look in table:
[233334444] [1111222] // <- i'm reversing the cell's order
+ using this method conversion number<->ascii string will be fast
+ the arithmetic (for example multiplication) will be slow (because for
carrying detection i'll have to divide a lot by 1000000000)

b) storing in one cell of the table values from 0 to (2^32)-1 (so all
bit's combination). But in this method i have to change base from
decimal to binary, which is too slow for very big numbers
so for example number 1111222233334444 will look in table:
[111111001010100110] [10010110011111000000001010101100] // <- this
numbers are in binary
+ using this method conversion number<->ascii string will be slow
+ the arithmetic (for example multiplication) will be fast

In my program i'm running a lot of arithmetic algorithms, and at the
beginning i'm printing the result. I was thinking that second method
will be much faster, but... Converting from number to ascii string
takes a lot lot of time (when number has more than 100000 digits). Do
anyone have fast base converting algorithm for very long numbers or
should i use method a) ?

GNU multiprecision library:
http://www.swox.com/gmp/
Mike Cowlishaw's decimal libraries:
http://www2.hursley.ibm.com/decimal/

Java, LISP, Perl, Python, REXX, Ruby, etc. all have bignum support,
some as add on libraries.

The bc and dc utilities support arbitrary precision calculations, and
are available for many platforms.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian.Inglis (AT) CSi (DOT) com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Keith Thompson
Guest





PostPosted: Wed May 31, 2006 11:00 am    Post subject: Re: Testing for EOF in file with binary data Reply with quote

jjf (AT) bcs (DOT) org.uk writes:
Quote:
David Warner wrote:
I am working on a C app that needs to read print files generated by lp
that contain HP LaserJet PCL codes. If the PCL contains binary data to
define a bit map to be printed on the page, either icon or soft-font
download, the EOF test ends prematurely and does not read the entire
file. How do I get around testing for EOF and not detect the EOF value
within the file? Am I missing something?
[snip]
What was wrong with the answers you got when you posted a similar
question to comp.lang.c on April 27?

He cross-posted (simultaneously) to comp.lang.c and
comp.lang.c.moderated. Articles posted to comp.lang.c appear on
servers as soon as they're propagated. Articles posted to
comp.lang.c.moderated appear when the moderator gets around to
approving and posting them. (He also cross-posted to comp.lang.c++,
which is almost always a bad idea.)

--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Keith Thompson
Guest





PostPosted: Tue Jun 06, 2006 11:23 pm    Post subject: Re: Testing for EOF in file with binary data Reply with quote

Richard Heathfield <invalid (AT) invalid (DOT) invalid> writes:
[...]
Quote:
These are not the droids you're looking for.

These are not the droids we're looking for.

--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Jordan Abel
Guest





PostPosted: Tue Jun 06, 2006 11:23 pm    Post subject: Re: Testing for EOF in file with binary data Reply with quote

2006-06-03 <clcm-20060602-0013 (AT) plethora (DOT) net>, Harald van D?k wrote:
Quote:
Kenneth Brody wrote:
Richard Heathfield wrote:

Joe Wright said:

The EOF character is not needed these days. You can stop C from checking
for it by opening your files in "rb" mode instead of "r" or "rt" mode.

The fopen function has no "rt" mode. Opening a file in "rt" mode invokes
undefined behaviour.

Is it undefined, or implementation-defined? (Or is a particular
implementation allowed to define its behavior for something which
the standard calls "undefined behavior"?)

It's undefined in standard C, and implementations are allowed to
"define UB". Most if not all do that in at least some ways. (A common
example is "\e", which is UB in standard C.)

A.6.5.15 Additional stream types and file-opening modes

Additional mappings from files to streams may be supported (§4.9.2),
and additional file-opening modes may be specified by characters
appended to the mode argument of the fopen function (§4.9.5.3).

and, from 4.9.5.3 (the fopen function)

The argument mode points to a string beginning with one of the
following sequences:/103/

103. Additional characters may follow these sequences.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Flash Gordon
Guest





PostPosted: Wed Jun 07, 2006 3:31 am    Post subject: Re: Testing for EOF in file with binary data Reply with quote

Kenneth Brody wrote:
Quote:
Richard Heathfield wrote:
Joe Wright said:

The EOF character is not needed these days. You can stop C from checking
for it by opening your files in "rb" mode instead of "r" or "rt" mode.
The fopen function has no "rt" mode. Opening a file in "rt" mode invokes
undefined behaviour.

Is it undefined, or implementation-defined? (Or is a particular
implementation allowed to define its behavior for something which
the standard calls "undefined behavior"?)

Implementations are allowed to define behaviour for instances of
undefined behaviour.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Flash Gordon
Guest





PostPosted: Wed Jun 07, 2006 3:31 am    Post subject: Re: Testing for EOF in file with binary data Reply with quote

David Warner wrote:
Quote:
Greetings!

I am working on a C app that needs to read print files generated by lp

If you are writing in C then you should not post to comp.lang.c++, C++
is a different language. If you are programming in C++ you should not
have posted to comp.lang.c. Cross-posting to both is rarely the correct
thing to do.

Quote:
that contain HP LaserJet PCL codes. If the PCL contains binary data to
define a bit map to be printed on the page, either icon or soft-font
download, the EOF test ends prematurely and does not read the entire
file. How do I get around testing for EOF and not detect the EOF value
within the file? Am I missing something?

<snip>

Open the file in binary mode rather than text mode.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Guest






PostPosted: Tue Jul 11, 2006 4:11 am    Post subject: Re: managed string library Reply with quote

Robert Seacord wrote:
Quote:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed
Strings" and released a "proof-of-concept" implementation of the managed
string library.

The specification, source code for the library, and other resources
related to managed strings are available for download from the CERT web
site at:

http://www.cert.org/secure-coding/managedstring.html

The following is a brief summary of the managed string library:

The managed string library was developed in response to the need for a
string library that can improve the quality and security of newly
developed C-language programs while eliminating obstacles to widespread
adoption and possible standardization.

I'm wondering whether or not you compared it to other available
libraries such as my own ( http://bstring.sf.net/ ) or James Anthill's
( http://www.and.org/vstr/ ) before engaging in this effort?

I understand that need for this solely from the security focus, but
your effort looks like it was born out of a very direct and narrow
approach that takes absolutely nothing else into account. Besides
being slow, the API is somewhat cumbersome, which makes inline usage
impossible. The whole charset filtering thing is not multithreading
friendly, and IMHO, a poorly focused solution to the system() problem.
Instead of hiding all the functionality in the managed string, why not
instead have a "filterstring()" function, or better yet, have a
"safesystem()" function? I have a more complete discussion in the
Bstrlib documentation (
http://bstring.cvs.sourceforge.net/*checkout*/bstring/tree/bstrlib.txt?pathrev=HEAD
, search for "Managed String Library").

Beyond just security concerns, there is 1) The "Software Crisis"
concern. This is the concern that writing software in a scalable
manner (i.e., writing millions of bug-free lines of code) is difficult
to do. 2) Performance. C's string operations often take an additional
O(n) penalty for having to implicitely call strlen(), or the
equivalent, redundantly. 3) The Clib's poor base functionality (no
insert/delete, split, replace, substring functions), additionally
hampered by its inability to deal with aliasing (so strcat(p,p) leads
to UB even though it has a compelling intuitive meaning).

Obviously, I think Bstrlib fares well by such criteria. My point,
though, is that the "Managed String Library" really does not do very
well at all. I think this is important because I think it will be hard
to compell developers to use Managed Strings (or TR 24731) if it
continues to propogate *other* weaknesses of the C std library while
only attempting to solving a very narrow problem.

I.e., I believe Bstrlib to be a better *SECURITY* solution than Managed
Strings (or TR 24731, or pretty much anything else short of a change in
language altogether) because it is more *compelling* to programmers to
use for *OTHER* reasons. I.e., it is not security gained by some
additionally necessary expended effort forcused solely on security, but
rather its a better way of dealing with strings overall which happens
to supply a good security system as a bonus. Bstrlib has been put
through its paces by other programmers who use it, regardless of their
reason (safety/security is certainly not the only reason). With
Managed Strings, it appears that you are starting from scratch.

Also unlike any other solution, the Bstrlib webpage also includes a
public statement on security, which gives a whole set of security
assertions that auditors can test the library against (
http://bstring.cvs.sourceforge.net/*checkout*/bstring/tree/security.txt?pathrev=HEAD
) How do Managed Strings compare in this regard? For example, in
terms of password input/manipulation, can your proposal make guarantees
that copies of string content be kept out of the heap (from a free or
realloc) outside of programmer control?

Since I have not submitted Bstrlib to the ANSI C committee, perhaps you
see this as a moot point. But what I would suggest to you is that you
at least *study* my library first, and see what ideas from it you
should incorporate into your proposal.

While I see the merit of your intentions, I don't see your effort as
quite there yet. Especially in light of open source alternatives such
as my library. At the very least, I think you should take libraries
such as mine as a yardstick by which to compare yours in developing it.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Barry Schwarz
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: Inseting the data at the midle of a file Reply with quote

On 09 Aug 2006 16:53:09 GMT, "ictrulz" <paimailbox (AT) gmail (DOT) com> wrote:

Quote:
Hi all,

I have one scenario related to file like this,

File Data:-
- - - - - - -

1
2
3
4
5
6
and file pointer is pointing to the position where number 4 is stored.

If I use simple file write interface then data will be written like
1
2
3
4
7 (Overwrite has happened )
6

But I want insertion to happen instead of overwrite like below,
1
2
3
4
7 ( Insertion should happen)
5
6
How to achieve data insertion in file?

You need to copy the data to a new file, performing the insertion at
the proper point. If you want the result to have the original file
name, you can delete the original and rename the new file.


Remove del for email
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
John Dallman
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: Binary Form Reply with quote

In article <clcm-20060809-0040 (AT) plethora (DOT) net>, neham.email (AT) gmail (DOT) com
(neha) wrote:

Quote:
How floats are stored in binary form.

This depends entirely on the hardware that you're running on and how
your C implementation uses it. All that C knows is that it has language
features for two sizes of floating-point variable. It is legal for them
to be the same physical size and stored in the same format. All C knows
about them is the amount of memory they take up, and their alignment
requirements.

Most modern processors use a system that's essentially logarithms to
base two. If that sentence doesn't mean anything to you, it works by
magic, and while the magic isn't completely reliable, it works pretty
well.

If you're asking about the formats used on the Windows machine you're
using to post, download the processor manuals from Intel's website.
They'll tell you all about it. They aren't especially easy reading, but
this comes under "things you should only tinker with if you have some
clear idea why you need to do it".

---
John Dallman, jgd (AT) cix (DOT) co.uk, HTML mail is treated as probable spam.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Michael Tiomkin
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: sum(2,4,3,5,-1,...) Reply with quote

Allan Adler wrote:
Quote:
I don't understand how to write functions that have variable numbers
of arguments. The only example I have to imitate is the one on p.289
of C: A Reference Manual, 2d ed (1987), by Harbison and Steele, for
a function named printargs, which is also my only source of information
about how to write such functions. I tried it on my PC running RH 7.1
and it compiles and runs fine. It depends, however, on an array at[]
for which &at[0] is the first argument. There is no natural choice
of an array related to the first argument of the function sum I'm
trying to write, but GCC complains that the first argument to sum
is not a pointer, so I think I have to give it one. Basically, I
wrote sum by imitating the code for printargs mentioned above.

#include <stdio.h
#include <stdarg.h

int sum(int *argtypep, ...)
{
va_list ap;
int argtype;
int total=0;
va_start(ap,argtypep);
while((argtype = *argtypep++) != 0) total += va_arg(ap,int);
va_end(ap);
return total;
}

The function sum is supposed to take a variable number of arguments
of type int and add them up. Thus, sum(0) returns 0 and sum(3,5,2,-7)
returns 3.

You cannot do this in C. In most implementations of C, e.g. using the
stack to push the arguments from right to left, the function with
ellipsis cannot determine what is the number of its arguments unless
there are some constraints on them.
One example: the number of arguments is the first arg:
int sum (int num_args, ...);
....
... sum(4, 3,5,2,-7) ... /* will return 3 */

Other example: you set a special number to end the sequence:
int sum(int first, ...); /* put -9999 at the end */
...
.... sum(3,5,2,-7,-999) ... /* will return -3 */

The problem with these solutions is that you cannot call sum(), with
no args, and get 0, like you can do in Scheme or C++.

In C++ you can use the default arguments for the 1st style, with the
number of args to sum:
int sum(int num_args=0, ...);

In this case your 'sum()' will return 0.

Michael
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
jacob navia
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: Standard Library of useful utilities in C... Reply with quote

Sunburned Surveyor wrote:
Quote:
I'm new to c programming, and I come to it from higher-level, object
oriented languages. I was hoping to find a standard library that
contained common structures and functions that would be used in many C
programs. As an example, I am looking for a standard implementation of
a hash table.

Does such a library exist? I checked out the GNU C Library, but it
didn't seem to have what I was looking for.

Does every C programmer implement this stuff from scratch?

Thanks,

Scott Huey

This is an ongoing discussion here.

There are people (like myself) that say that the language should provide
with standard implementations of common data structures like hash tables
and others, so that code would have a higher abstraction level. This
point of view has been the driving idea behind the lcc-win32 compiler
system.

Other people here say that C should be kept "low level", without
offering anything more than a primitive set of functions that
is known as "standard library". Bugs included of course, to maintain
compatibility with all errors of the past.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Hans-Bernhard Broeker
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: Inseting the data at the midle of a file Reply with quote

ictrulz <paimailbox (AT) gmail (DOT) com> wrote:

Quote:
How to achieve data insertion in file?

By creating a modified copy. Inserting data in the middle of a file
doesn't work any better than inserting words in the middle of a
paragraph in a printed book.

--
Hans-Bernhard Broeker (broeker (AT) physik (DOT) rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Douglas A. Gwyn
Guest





PostPosted: Thu Aug 10, 2006 9:11 am    Post subject: Re: Standard Library of useful utilities in C... Reply with quote

"Sunburned Surveyor" <redefined.horizons (AT) gmail (DOT) com> wrote in message
news:clcm-20060809-0032 (AT) plethora (DOT) net...
Quote:
Does every C programmer implement this stuff from scratch?

No, in fact there are a large number of C libraries
for various purposes available freely on the net.

The *standard* library is intentionally kept small;
it is limited mainly to the set of functions that had been
proven generally useful across essentially all C platforms
at the time C was standardized. (The more system-specific
part of the Unix C library was taken over by the POSIX
standard.)

Experienced C programmers and established programming
shops have built up their own programming support libraries.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated) All times are GMT
Goto page Previous  1, 2, 3, 4 ... 11, 12, 13  Next
Page 3 of 13

 
 


Powered by phpBB © 2001, 2006 phpBB Group