comp.lang.c.moderated
  Home FAQ Contact Sign in
comp.lang.c.moderated only
 
Advanced search
April 2008
motuwethfrsasuw
 123456 14
78910111213 15
14151617181920 16
21222324252627 17
282930     18
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.c.moderated Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  Is malloc() function provided in <stdlib.h> thread-safe?         


Author: climber.cui
Date: Apr 21, 2008 11:20

Hi all,
Does anyone have experience on the thread-safty issue with malloc()?
Some people said this function provided in stdlib.h is not thread-
safe, but someone said it is thread safe. Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?
How could i find out?
I am using the C library coming with GNU linux distribution.

thanks a lot.

tony
--
comp.lang.c.moderated - moderation address: clcm@plethora.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.
7 Comments
  C API Design         


Author: Al
Date: Apr 21, 2008 11:19

Hi there,

I haven't kept up with the latest C best practices. In adapting
(wrapping, mostly) a C++ API which throws on error, which of these might
the better alternative, or are there other options I haven't considered?

/* Assume: */

typedef struct { ... } Error;
struct Foo;

/* Parametric (stateless) version: */
Foo* CreateFoo (int ctorparam, Error *const error);
bool PrintFoo (const Foo *const foo, Error *const error);
bool ReleaseFoo(const Foo *const foo, Error *const error);

/* Static (stateful) version: */
Foo* CreateFoo (int ctorparam);
bool PrintFoo (const Foo *const foo);
bool ReleaseFoo(const Foo *const foo);
Error* LastError ();
Show full article (1.65Kb)
4 Comments
  Problem in writing structure to Binary file in C lang         


Author: zehra.mb
Date: Apr 18, 2008 14:11

Hi,
I had written application for storing employee data in binary file and
reading those data from binary file and display it in C language.
But I face some issue with writing data to binary file.
Here is my part of my code.

struct cust_data
{
int nCAFID;
char *szFirstName;
};

typedef struct cust_data CUST_DATA;
CUST_DATA *pCustdata = NULL;
int AddRecord()
{
FILE *fp;
fp = fopen("Input.dat","ab+");
return fp;
pCustdata = malloc(sizeof(CUST_DATA));
Show full article (1.47Kb)
3 Comments
  How should I reopen stdout, so that I can change stream orientation using fwide()         


Author: Terry
Date: Apr 18, 2008 14:11

I want to reopen stdout, so that I can change stream orientation on
stdout using fwide().
Can this be done using only C library routines?
Thanks!
--
comp.lang.c.moderated - moderation address: clcm@plethora.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.
2 Comments
  Working with Cash and uses of Typedef         


Author: Philluminati
Date: Apr 16, 2008 14:57

I am writing a poker game which needs to work with cash. I am aware
that there are problems with floats that make them unsuitable for
storing money values. On top of this I may be expected to do
operations such as £10.52 / 3. Which data type should I use instead?
Is there an Industry standard one?

Further to this, is anyone away of legally what the obligations would
be when the outcome is 3.566666667? does the customer get 56 or 57p?
Do I need to track the remaining .003333 and use it in other
operations?

And finally, why do I see people typedef values in C and, for example,
use size_t rather than an int? Why is the type hidden like this?
Surely it can lead to bugs and changing a data type later in
development can allow bitwise and maths operations to become un-
trustable? In my own applications I have been typdef'ing structures
merely to remove the requirement to write "struct" everywhere and I
see how shortening the name of unsigned long to ulng would be useful
but I don't see it's benefit in some cases. So why do people use it?

I'm sorry if these questions seem stupid or simple but I'm new to C
and I can't find that many resources for C.
Show full article (1.40Kb)
5 Comments
  Ambiguous errata solutions for K&R2         


Author: Ioannis Vranos
Date: Apr 16, 2008 14:56

In K&R2 errata page
<http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html>
there are some ambiguous errata, for which I propose solutions. Any
comments are welcome.

Ambiguous errata (mentioned first) of "The C Programming Language" 2nd
Edition errata page
(http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html), and
proposed solutions that should be added to the errata page exactly as
they appear:

1. "119-121(§5.11): The qsort discussion needs recasting in several ways.
First, qsort is a standard routine in ANSI/ISO C, so the rendition here
should be given a different name, especially because the arguments to
standard qsort are a bit different: the standard accepts a base pointer
and a count, while this example uses a base pointer and two offsets".

Proposed solution:

Rename the "qsort" references, declarations and definitions as "sort" in
the entire section 5.11.

2. "Also, the comparison-routine argument is not treated well. The call
shown on p 119, with an argument
Show full article (5.25Kb)
1 Comment
  typedef a struct         


Author: Taras_96
Date: Apr 16, 2008 14:56

Hi everyone,

You can typedef a struct by using the following

typedef struct x {} X, *PX;

Now, I can understand the use of the typedefs, X and PX. They allow
you to declare the structs without having to use the struct keyword.
However, I'm not quite sure of the usefullness of the struct tag 'x'.

I seem to remember someone telling me that it had something to do with
resolving circular dependencies, when file A depends on file B, and
vice versa. Also, it may have something to do with structs that refer
to themselves (from the FAQ):

1.14: I can't seem to define a linked list node which contains a
pointer to itself.

A: Structures in C can certainly contain pointers to themselves;
the discussion and example in section 6.5 of K&R make this
clear. Problems arise if an attempt is made to define (and
use)
a typedef in the midst of such a declaration; avoid this.
Show full article (1.21Kb)
3 Comments
  signal catching not work         


Author: Terry
Date: Apr 16, 2008 14:56

The code is supposed to catch two segment fault, but the second is
always missing on my machine. Could anyone tell me why this code
doesn't work as expected?

#include
#include
#include
#include
#include

jmp_buf buf;

void sighandler(int a){
static int i=0;
longjmp(buf, ++i);
}

union {
int *p;
int i;
} a;

int *p;
Show full article (1.15Kb)
9 Comments
  Promotions while delivering parameters         


Author: Magi Su
Date: Apr 13, 2008 00:41

Hello everyone!

I am a student learning Expert C Programming. One interesting topic I have
found is that, which the book told me, when we use K&R style declaration
and definition of functions:
int kandr();
....
int kandr(p1,p2)
int p1; char p2;
{}
the 'char' parameter p2 is promoted to 'int' while pushing into stack;
however, when we use ANSI style:
int ansi(int p1,char p2)
{}
the parameter p2 is pushed as 'char'.

I have written a program to try it out:

------------------promote1.c----------------------
void fun1(int,char);
void fun2();
Show full article (1.79Kb)
7 Comments
  detect non reentrant function         


Author: SHP
Date: Apr 13, 2008 00:41

Hi
Is there a way to detect the usage of non reentrant functions at
compile time? Any gcc option?

thanks
shp
--
comp.lang.c.moderated - moderation address: clcm@plethora.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.
2 Comments
 
1 2