Live data from Hacker News

Resume in C

gist.github.com

81–90 of 115 posts

Re: Resume in C

#81
post #5

Wow, I didn't know this was valid C code, it's pretty convenient. school_t uiuc = { .school = "University of Illinois at Urbana-Champaign", .location = "Urbana, IL", .program = "BS Computer Science", .started = 1251158400, .left = 1336608000, .accomplishments = { "Minor in International Studies in Engineering, Japan", "Focused on systems software courses", NULL } };

It's a C99 feature (I think?) -- designated literals. They're absolutely wonderful.

I so, so wish C++ would adopt this feature.

Re: Resume in C

#83
post #34

Earlier quoted context omitted.

> If we are being idiomatic I would suggest pointer arithmetic to iterate instead of using a counter i. Well, the CVE guys need to keep their job.

He's already iterating by using null termination instead of based on array bounds. I am suggesting he do it in the more common way. On another topic, I have noticed you post this sort of trollish c bashing on almost every hn thread about c. It's fine that you prefer something else, but maybe time to give it a rest?

Someone needs to spread the gospel of safe systems programming to young minds not exposed to the existing alternatives, before C grew out of UNIX.

If C didn't need this kind of attention to safety, Clang, GCC and others wouldn't have all those nice analyzers built-in, not MISRA would be required.

Besides, looking for my post history and fellow comments, I am not alone in this.

Re: Resume in C

#84

Earlier quoted context omitted.

Say, somebody allocated one of the strings with malloc or strdup and put a free(), but mixed up when to call free() and when not.

OK but that's an issue with using char* where does the union issue come in? I could understand an issue with a union between char* and, say, int or some other pointer, but I don't see what specific issue would arise from a union between the exact same pointer types.

  union {
    char* x;
    char* y;
  };

  ...

  if (/*smth*/) {
    x = "Hello";
  } else {
    y = strdup("Hello");
  }

  ...

  if (/*smth*/) {
    free(y);
  }
It is possible to screw up the condition to calling free(), especially in more involved code.

Re: Resume in C

#85

Earlier quoted context omitted.

It's subjective. It feels more c like and natural to me to write while (foo->bar) and not while (foo[i].bar). The latter feels like the way you would do it somewhere else, grafted onto C. But it's not wrong, I don't have deep qualms with it, and that's why I put it last on my list.

It's not subjective. Intel's guidelines for writing vectorizable code: Prefer array notation to the use of pointers. C programs in particular impose very few restrictions on the use of pointers; aliased pointers may lead to unexpected dependencies. Without help, the compiler often cannot tell whether it is safe to vectorize code containing pointers. Source: https://software.intel.com/sites/default/files/8c/a9/Compile…

What are the odds this turns out to be practical advice for this example? Are you going to write all your loops like that because someone at Intel told you it was a good idea, or are you going to measure it when it's seen to be a problem?

Re: Resume in C

#88

Earlier quoted context omitted.

It means that GCC will allow/support this even if you set it to std=c89 or std=c90.

Won't that only be supported in gnu89 or gnu90 mode?

The GNU modes just enable additional features which conflict with plain C. Any feature which can coexist with plain C will be enabled in the regular C modes too. For example, __typeof__ is enabled everywhere, because the compiler is allowed to do just about anything it wants with a __ prefix, but plain typeof is only enabled in the GNU modes, since it could cause valid C programs using "typeof" for their own purposes to fail to compile.

Re: Resume in C

#89
post #83

Earlier quoted context omitted.

He's already iterating by using null termination instead of based on array bounds. I am suggesting he do it in the more common way. On another topic, I have noticed you post this sort of trollish c bashing on almost every hn thread about c. It's fine that you prefer something else, but maybe time to give it a rest?

Someone needs to spread the gospel of safe systems programming to young minds not exposed to the existing alternatives, before C grew out of UNIX. If C didn't need this kind of attention to safety, Clang, GCC and others wouldn't have all those nice analyzers built-in, not MISRA would be required. Besides, looking for my post history and fellow comments, I am not alone in this.

I think Peter Van Der Linden would agree. He states in Deep C Programming that the separation of the compiler from the linter, and I assume by extension semantic analysis tools as well, was a mistake in retrospect. It's good to see that compilers like Clang are bringing them back together in a way.

One does have to be more careful when writing C but I don't "blame" C for unsafe code. It's the kind of language that assumes the programmer know what they're doing. In this regard it is very unforgiving.

Re: Resume in C

#90
post #70

Earlier quoted context omitted.

char * argv is a pointer to a string (or a single character). char ** argv is a pointer to an array of pointers to strings. The latter is used since it allows for multiple arguments in (the number being `int argc`). This picture shows the second example in terms of pointers: http://www.londonquilters.org.uk/ctext/pic511.gif

Wouldn't second simply segfault when you try to access it?

Nope, neither will segfault on the initial access.

  char ** argv
is a null terminated array in C according to the C standard. (EDIT: see clarification below) C doesn't care about types at all and you can abuse this by casting pointers to different (sometimes incompatible types). The second argument to main (argv) it set up by the initialization code and has the same space as a pointer regardless if it's a string, array of strings, struct, integer etc...

The existing structure will simply be interpreted as that new type like so:

                String1       String2    String3     String4
  char ** a2: |0x41414141 |0x42424242 |0x43434343 |0x00000000 |
              +-----------+-----------+-----------+-----------+
  char * a1 : |41|41|41|41|42|42|42|42|43|43|43|43|00|00|00|00|
  
  printf("%s\n", a1);
  > AAAABBBBCCCC
That being said, some compilers (clang) will emit an error on the improper type, like so:

  test.c:3:5: error: second parameter of 'main' (argument array) must be of type
        'char **'
  int main(int argc, char * argv)
      ^
  1 error generated.
Post reply on HN