assembly in future C standard HCF Gerry Wheeler


    Sponsored Links


  • 1. memory mgmt problem
    I wrote this code to create and store some structs. This code occasionally blows up in FreeItem, and I can't figure out why. I only see problems with very large amounts of data, and then only rarely, making it harder to debug. Do you see any flaws or have any suggestions for improving the routines? I declare a data structure: typedef struct { char this[256]; int that; } Item; // this is just an example, usually item is more complex and another struct to hold these structs: typedef struct { int entries; Item **item; } List; before first use: List list; list.entries = 0; list.item = NULL; We add items to the list with: void AddItem(List *d, Item *item) { if( (d->item = (Item **)realloc(d->item, (d->entries+1)*sizeof(*d->item))) == NULL) { printf("AddItem: couldn't reallocate memory for entry %d\n", d->entries); exit(1); } if( (d->item[d->entries] = (Item *)malloc(sizeof(*item))) == NULL) { printf("AddItem: couldn't allocate memory for entry %d\n", d->entries); exit(1); } memcpy(d->item[d->entries++], item, sizeof(*item)); } // AddItem And when done, call this to free void FreeList(List *d) { int i; for(i = 0; i < d->entries; i++) free(d->item[i]); free(d); // this line is sometimes the source of memory errors }
  • 2. Recursing code problem
    I am using Interactive C with my handboard (68HC11) development system but I've got a problem that I am asking for help with. I am not new to C but learning all the time and I just cant see how to overcome this problem. Symptom: Programs fail ' Runtime error' which equates to a stack error. This is because my code is like going around and around (a snake chasing its tail is a term I've seen used) but I cant quite come to grips with how to overcome this problem. Should I post some of the code up on this group for people with a better knowledge of this problem to make suggestions - I feel its probably something not difficult to understand but I just need a little guidance here. Jeff
  • 3. types, constants and casting
    When assigning or testing equality between a type and a constant, should the constant be casted to the type? I.e. should fork() == -1 be written as fork() == (pid_t)-1? should uid = 45 be written as uid = (uid_t)45? Is the casting necessary? Does it increase portability? Browsing some projects, I noticed that -1 is casted but not other values, i.e. chown("somefile", 45, (gid_t)-1). In short, what is the best practice. TIA -Tom

Re: assembly in future C standard HCF Gerry Wheeler

Postby Walter Banks » Sat, 04 Nov 2006 22:35:39 GMT

As this thread wanders off topic this industry was introduced to a new
mnemonic in Byte article about decoding the undocumented
Motorola 6800 instructions. The HCF (Halt Catch Fire) opcode $DD
or $D9. HFC locked up the processor and cycled the address bus
The author of that article was Gerry Wheeler.

Gerry Wheeler, 54, died October 15, 2006, advanced non-Hodgkins
lymphoma cancer. Gerry made significant contributions to the technology
of the embedded systems world and was a key part of the development
of many household name products.

Programmer, Ham KG4NBB, author, father, husband, active commuity
participant Gerry will be missed by all.


Similar Threads:

1.assembly in future C standard

Peter Nilsson < XXXX@XXXXX.COM > wrote:

(Crossposted to comp.std.c, with followups directed there, hopefully
 appropriately.  The original post discussed the possibility of whether
 __asm or something similar to it would be added to the C standard.)

> Contrary to Richard Heathfield's categorical statement, it is not an
> absolute given that there will never be an asm keyword in C. But it
> is unlikely because it's already clear that the asm keyword in C++ has
> not served to truly standardise the syntax of inline assembly.

One idea that was not mentioned in the original thread (I imagine for
good reason, because it's a half-baked and probably stupid idea that
occurred to me reading your post) would be to allow for some kind of
conditional assembly, just perhaps something like

#pragma assemble
#pragma X86 /* Inner pragma's implementation-defined */
  /* Inline assembly, which the implementation can ignore or not */
#pragma no-assemble
  /* Stock C code for implementations that can't or won't accept the
   * assemble pragma: */
  for( i=1; i < 10; i++ ) {
    /* ... */
#pragma end-assemble

The end result would be something like "If the implementation attempts
to inline the assembly code contained within a #pragma assemble
directive, the behavior is implementation-defined.  Otherwise the
assembly code shall be ignored and the C code contained within any
corresponding #pragma no-assemble directive shall be compiled as
though no directives were present."  It would require adding some
duties to the #pragma directive, but it would allow implementors to
take a reasonable shot at using targetted assembly instructions when
appropriate and available, and reverting to ordinary C otherwise.

I'm sure there are reasons why this is stupid and/or impossible, or it
would have been done already :-)

> At the end of the day, the committee could probably spend many man
> weeks deciding issues on an __asm keyword, but for what? Most
> implementations will keep their existing syntax, and most programmers
> who use inline assembly will no doubt continue to prefer the localised
> syntax because it's less cumbersome than any standard syntax.

Indeed, but it's an interesting thought experiment to consider how the
committee *might* add assembly to C if they chose to do so.  (Well,
interesting to me, at least.)

C. Benson Manica           | I *should* know what I'm talking about - if I
cbmanica(at)      | don't, I need to know.  Flames welcome.

Return to c


Who is online

Users browsing this forum: No registered users and 75 guest