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

Pages: 1-4041-8081-

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-24 12:24

No.

Name: Anonymous 2009-03-24 12:27

Use packed structures

Name: Anonymous 2009-03-24 12:29

>>1-3
SPAWHBTC

Name: Anonymous 2009-03-24 12:32

Actually there must be something not portable... and that's demonstrated by tinyos documentation

These structures MUST be external structs (nx_struct), and all of their fields MUST be external types (nx_*), for two reasons. First, external types ensure cross-platform compatibility [1]....

Name: Anonymous 2009-03-24 12:33

>>3

OP speaking: what's that?

Name: Anonymous 2009-03-24 12:33

>>5
Cargo cult programming is fun.

Name: Anonymous 2009-03-24 12:35

>>6

It's SHOW SOME ADAPTABILITY YOU FAGTARD.

Name: Anonymous 2009-03-24 12:35

>>7

wut

Name: Anonymous 2009-03-24 12:37

NO

Name: Anonymous 2009-03-24 12:42

>>9
Instead of taking confused cues from the documentation of some random project which may or may not have shit to do with anything, you could try reading the goddamn C standard.

Name: Anonymous 2009-03-24 12:43

>>11
Good Idea. I'll check it! Have you got some interesting pointers?

Name: Anonymous 2009-03-24 12:54

>>12
void* is a pretty good one.

Name: Anonymous 2009-03-24 12:57

>>13
Well, shit.

Name: Anonymous 2009-03-24 12:58

>>12
 NullPtr

Name: Anonymous 2009-03-24 13:02

>>15
That's funny.

Name: Anonymous 2009-03-24 13:05

ぬるぽ

Name: Anonymous 2009-03-24 13:06

>>13
You mean void *.

Name: Anonymous 2009-03-24 13:12

Serialization Serialization Serialization

Name: Anonymous 2009-03-24 16:28

>>18
If C's tokenizer were sane, that's what I'd mean. However it has no requirement that tokens must have whitespace in between.

Name: Anonymous 2009-03-24 19:42

The proper way is to marshal the data manually into the stream. You should really treat a struct has a local thing only.

Name: Anonymous 2009-03-24 20:31

>>21
No. The language is there for a reason, not so you can do extra work when you don't need to.

Name: Anonymous 2009-03-24 20:40

>>22
No. The language is there for a reason, not so you can do extra work when you don't need to.
Did you forget this thread was about C somewhere in the heat of the argument?

Name: Anonymous 2009-03-24 22:03

>>23
No.

Name: Anonymous 2009-03-25 15:33

>>1
They aren't. Use XDR.

Name: Anonymous 2009-03-25 15:52

Use a JSON parser
Thread over

Name: Anonymous 2009-03-25 15:56

>>22
What about endianess if the struct contains multi-byte integers? Will the language just magically get it right when sending, or does one have to ensure that it's converted correctly?

Name: Anonymous 2009-03-25 16:08

>>27
Endianness issues are not relevant unless you're programming on Macs.

Name: Anonymous 2009-03-25 16:10

>>28
I stopped reading at "unless." Nobody cares about Macs.

Name: Anonymous 2009-03-25 16:30

>>28
WORST TROLL OR WORSTEST TROLL

Name: Anonymous 2009-03-25 16:32

>>29
How do you know he was talking about Macs unless you continued reading?

Name: Anonymous 2009-03-25 16:34

>>30
WORCHESTERSHIRE TROLL

Name: Anonymous 2009-03-25 16:42

>>28
>Endianness issues are not relevant unless you care about portability.

Fix'd that for you.

Name: Anonymous 2009-03-25 16:43

>>31
EXPERT READING

Name: Anonymous 2009-03-25 17:03

>>31
EXPERT READING COMPREHENSION
I smirked. Good one.

Name: Anonymous 2009-03-25 17:03

Actually it's obvious that little-endian is the superior byte ordering. Since new Macs are little-endian too, you should stop caring and declare forced obsolescence over anything big-endian.

Are the PPC chips in the PS3 and X360 big or little endian? If they are big endian, it's no surprise the former is overpriced and doesn't sell and the later crashes as much as it does.

Name: Anonymous 2009-03-25 17:08

>>36
What the fuck does endianness have to do with the price or stability of a processor? It's just a design decision. In fact, many processors can be either big- or little- endian.

It's not like converting endianness is hard, anyways, it's just something you have to remember to do.

I will admit that little-endian, although at first unintuitive, does have some great benefits. For example, it's easier to convert larger integers to smaller ones in a little-endian system.

Name: Anonymous 2009-03-25 17:12

>>37
Endianess is relevant because of YHBT

Name: Anonymous 2009-03-25 17:54

>>27
Why would you need multibyte integers anyway? They are a solution in search of a problem.

Name: Anonymous 2009-03-25 19:43

>>37
I will admit that little-endian, although at first unintuitive
You've obviously never used assembler. Ever.

does have some great benefits.
Big-endian has exactly one, and it's not "great".

Name: Anonymous 2009-03-25 20:03

>>37
Someone hasn't read his Knuth recently.

Name: Anonymous 2009-03-26 6:46

>>25
This post has answered OP's question.
Stop posting

Name: Anonymous 2009-03-26 9:48

>>42
Hi! How are you feeling today?
I just woke up and am eating breakfast! Mmmm.

Name: Anonymous 2009-03-26 9:56

Convert everything to network byte order.

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

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