Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C Structs

Name: Anonymous 2009-03-24 12:22

Hi fags.

I need to know how portable c structs are for data transmission: are the fields in a fixed position determined by some standard?

Name: Anonymous 2009-03-26 10:14

>>42
The OP's posts have been the least interesting parts of this thread by far. Threads don't exist in function of their first post.

Name: Anonymous 2009-03-26 10:38

I agree with >>45-san. Threads should end of their own volition.

Name: Anonymous 2009-03-26 11:12

Also, if you close a thread as soon as the question is answered, that eliminates the possiblity that someone else can contribute a better answer to the question later.

Name: Anonymous 2009-03-26 16:39

>>47
I don't think you understand the point of /prog/.

Name: Anonymous 2009-03-26 16:59

>>46,47
Yes let's improve on that answer.  Let's discuss how OP should indent his struct's.

Name: Anonymous 2009-03-26 18:49

HAY GUYS Check out my variadic strdup


#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

char *strdupv(int count, ...) {
  va_list ap;
  int i,n=0;
  char *r,**s;

  s = malloc(count * sizeof(char*));
  if(!s)
    return NULL;

  va_start(ap,count);
  for(i=0;i<count;i++) {
    s[i] = va_arg(ap,char*);
    n += strlen(s[i]);
  }
  va_end(ap);

  r = malloc(n+1);
  if(r) {
    *r = 0;
    for(i=0;i<count;i++)
      strcat(r,s[i]);
  }

  free(s);
  return r;
}

Name: Anonymous 2009-03-26 20:37

>>50
Have you considered using four spaces for indentation? It helps for readability.

Name: Anonymous 2009-03-26 20:42

>>51
Actually, numerous academic papers have been written on the subject and extensive research has been held. All such research and papers have pointed towards two spaces being the optimal indentation amount with regards to code readability, with a small number claiming three.

Name: Anonymous 2009-03-26 20:51

>>52
link to said research, or GTFO gnufag.

Name: Anonymous 2009-03-26 20:58

>>53
My AI lecturer has a number of sources for it. I will ask him next lecture for you Anon.

Name: Anonymous 2009-03-26 21:00

>>53
Actually, I do not believe two- or three-space indentation is compatible with GNU style (or the GPL).

Name: Anonymous 2009-03-26 21:02

>>50
here, i made your code a bit more readable for you:
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

char *strdupv(int count, ...)
{ va_list ap;
  char *r = NULL, **s = malloc(count * sizeof(char *));
  if(s)
  { int i, n = 0;
    va_start(ap, count);
    for(i = 0; i < count; ++i)
    { s[i] = va_arg(ap, char *);
      n += strlen(s[i]); }
    va_end(ap);
    r = malloc(n + 1);
    if(r) for(*r = i = 0; i < count; ++i) strcat(r, s[i]);
    free(s); }
  return r; }

Name: Anonymous 2009-03-26 21:05

>>55
two-space indentation is the gnufag standard.

http://www.gnu.org/prep/standards/html_node/Formatting.html

Name: Anonymous 2009-03-26 21:06

>>56
actually, why not do this instead?
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

char *strdupv(int count, ...)
{ va_list ap;
  char *r = NULL, char *s[count];
  int i, n = 0;
  va_start(ap, count);
  for(i = 0; i < count; n += strlen(s[i++])) s[i] = va_arg(ap, char *);
  va_end(ap);
  r = malloc(n + 1);
  if(r) for(*r = i = 0; i < count; ++i) strcat(r, s[i]);
  return r; }

Name: Anonymous 2009-03-26 21:14

>>56
>>58
YEAH THATS REAL PURTY

Name: Anonymous 2009-03-26 21:15

>>57
One-space is the ANONIX standard. Let's use that!

Name: Anonymous 2009-03-27 2:10

>>57
8 space tab is the Linux kernel standard. Best tab width, or bestest tab width?

Name: Anonymous 2009-03-27 6:22

In future I think I'll write my whole code on one line.

Name: Anonymous 2009-03-27 6:28

I prefer 5 space tabs myself.

Name: Anonymous 2009-03-27 7:16

>>61
FUCK YEAH WIDE SCREENS

Name: Anonymous 2009-03-27 7:32

>>64
3 80-column terminals! FUCK YEAH!

Name: Anonymous 2009-03-27 9:18

OP Speaking

>>28
...macs or embedded systems. And that's me. Actually endianness *do* have importance.

However, I'm not afraid of endianness. I'm just asking about structs. Ok, thanks for who replied me telling that structs are not usable for my goals, but actually I'm searching for a precise document that declares them as not standard.

Does it exist?

Name: Anonymous 2009-03-27 9:33

>>66
It's no a c thing - it's related to the underlying architechure your working with, which the c compiler will have to fit with that. Some machines require things to be aligned on 32-bit boundaries for example, so a struct such as:

struct foo {
  char foo1;
  int  foo2;
};

will end up padded with a 3 byte gap between foo1 and foo2.

this is a helpful link to explain it
http://www.eventhelix.com/RealtimeMantra/ByteAlignmentAndOrdering.htm

Name: Anonymous 2009-03-27 9:47

>>67
What about his working with?

Name: Anonymous 2009-03-27 10:49

>>66
The ISO C standard is a good place to start.

>>57
It is pretty telling that the GNU coding standards are the ugliest known to man, and that they are official because they're RMS' personal preference. Is there anything about that man that is not pig disgusting?

Name: Anonymous 2009-03-27 11:44

>>69
his flute playing is second to none

Name: Anonymous 2009-03-27 12:07

>>66
Nobody cares about embedded systems

Name: Anonymous 2009-03-27 14:05

>>71
2/10

Name: Anonymous 2009-03-27 17:07

>>69
He's got a foresight that makes the rest of society look like real dullards.

Name: Anonymous 2009-03-27 18:39

>>69
He can crank dat soulja boy big time

Name: Anonymous 2009-03-27 20:56

>>73
If by foresight you mean sub-1% market share, then sure.

Name: Anonymous 2009-03-27 21:04

>>74
Oh god. He doesn't even put down the computer while he does that.

Name: Anonymous 2009-03-27 21:11

>>75
No, that's what I meant. Just because the population are ignorant of some issues does not make those issues irrelevant. Take the work on sub-atomic theory for example. It was just a bunch of geeks that messed around with some useless theory right? I mean, we would have invented the microwave and nuclear energy without that knowledge right?

Name: Anonymous 2009-03-27 21:19

>>77
s/s\ what/s\ not\ what/

Name: Anonymous 2009-03-27 21:43

>>77-78
That's a terrible example.  You could say the same about any other raving lunatic.

Name: Anonymous 2009-03-28 7:20

>>79
The difference between a raving lunatic and a soothsayer is time.

Name: Anonymous 2009-03-28 8:05

>>79
Yeah, I do admit the example is terrible. How about the strategy of resource conservation; just because many people can afford to finance a wasteful lifestyle doesn't mean they should. Some smart people took the initiative to educate the rest of society to take responsibility for our consumption of the Earth's resources. If we don't, our global society will literally lose everything in no time at all.

To imagine an outcome of society collapse on a global scale as a result of unrestricted resource consumption requires a fair amount of intelligence and foresight that wouldn't exist in the 1900's.

Likewise, most people have an elementary understanding of what RMS's message and fail to understand his deeper points as well as the implications of them. RMS has consistently shown to be correct as a thinker far beyond his time and people fail to understand his message because of plain ignorance.

Name: Anonymous 2009-03-28 13:11

>>81
Expert troll

Name: Anonymous 2009-03-28 15:39

>>77
What does microwave have to do with "sub-atomic theory"?

It looks like you, my friend, is plain ignorant, lack any amount of intelligence or foresight and is a thinker far behind your time.

Name: Anonymous 2009-03-29 12:31

>>83
Your autism is showing but that doesn't redeem >>77's poor choice of an example.

Name: ​​​​​​​​​​ 2010-10-22 0:43

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List