Archives
2010 June 2010 May 2010 February 2010 January 2009 October 2009 September 2009 April 2009 February 2009 January 2008 July 2008 May 2008 April 2008 March
Welcome back.
» forget me
Subscribe:
Login:
|
| C Arrays |
| Sun September 13th, 2009 at 7:35 PM PDT |
Oh hi, haven't been here in a while, just thought I'd stop in and rant a little bit.
I know a lot of people (myself included) like to rip on Java for its obnoxiously verbose syntax, like how the standard library frequently makes you write the same thing out 3 or 4 times in one statement.
Well I've been working in C a lot lately, and suffering from the same problem. Say I want to declare a dynamically-allocated array of IP addresses, with an initial size of 10. In C that means typing this:
struct in_addr *array = (struct in_addr *) malloc(10 * sizeof(struct in_addr));
Seriously now C, is that really necessary? I just typed out struct in_addr 3 times in one statement.
Yeah, I know you can leave out the explicit cast to struct in_addr *, but then when you turn on compiler warnings you get yelled at a lot, and I like my compiler to check stuff for me.
Luckily in C++ they have made this a little better, by making you not have to call malloc to allocate memory, and not having to multiply by the datatype size when making an array, and not even having to specify the struct keyword:
in_addr *array = new in_addr[10];
Cool. But I'm stuck using C for my university networking assignments, so I think I'm just going to write some preprocessor macros to do the typing for me. ;P
-WRF
|
|
»
(make a comment)
|
Comments:
no comments to show
|
| Shoutbox |
Anonymous:
lonely shoutbox :(
Mon April 7th, 2008 at 5:09 PM PDT
|
Anonymous:
hello
Mon April 7th, 2008 at 5:12 PM PDT
|
Anonymous:
o hai
Mon April 28th, 2008 at 12:31 PM PDT
|
CHIZUBAGA:
I CAN HAZ CHIZUBAGA!!!!!!!
Wed January 20th, 2010 at 12:58 PM PST
|
Not Jeremy:
o hai remember when i threw hot sauz in yer eye. lulz
Thu January 28th, 2010 at 11:28 AM PST
|
JEREMY:
MOAR NAPKINS DURR HURR
Thu February 11th, 2010 at 9:33 AM PST
|
Shoutbox:
I wuz on a DAtZ.. haffing chizubaga!! Om nom nom nom!!
Wed May 26th, 2010 at 1:04 PM PDT
|
Totally not anyone you know:
Problem?
Thu June 3rd, 2010 at 2:09 PM PDT
|
Random Randomstein:
Shitpickle.
Fri June 11th, 2010 at 6:04 PM PDT
|
|