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.
Resume in C
81–90 of 115 posts
Re: Resume in C
#82Re: Resume in C
#83Earlier 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?
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
#84Earlier 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
#85Earlier 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…
Re: Resume in C
#86Cute, but it probably wouldn't make it past the HR filter.
> No, I don't distribute my résumé like this.
Re: Resume in C
#87Reminds me of Major Hayden's man page résumé[0] [0] http://majorhayden.com
Re: Resume in C
#88Earlier 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?
Re: Resume in C
#89Earlier 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.
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
#90Earlier 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?
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.