Talk:A Little C Primer/C Variables, Declarations and Constants

Proofreading
This sentence: "Variable names can be at least 31 characters long, though modern compilers will always support longer names." is confusing. Should it instead say "at most 31 characters long"? Also, it seems like there should be some data or standard for when the maximum length was 31. Jackhill (discuss • contribs) 18:08, 26 July 2011 (UTC)

Some clarification required
The sentence "The name of a structure defines a variable, not an address. If the name of a structure is passed to a function, the function works only on its local copy of the structure. To return values, an address must be specified:" on it own with the current one-liner example code is quite hard to grasp without further explanation or a more extensive example. I had to re-read it multiple times and still I'm not 100% sure I understand what is meant by it. Using "setstruct" as an example function name adds even more to the confusion, since it might imply that it is a default available C function.

I would change the last sentence "To return values, an address must be specified:" to something like "To have the called function alter the element values of a struct while the caller function has to continue to work on the altered values, the address of the struct must be given to the called function". The values aren't actually 'returned' in the classical way, using the return statement.

A different example would explain it all:  ...  int main {    struct person m;                         /* Declare an instance of it. */    strcpy( m.name, "Coyote, Wile E." );     /* Initialize it. */    m.age = 31; alter_age( m ); printf( "Age: %d\n", m.age );           /* Still displays 31. */    alter_age( &m );                         /* Note the use of '&'. */    printf( "Age:  %d\n", m.age );           /* Displays 42. */    return 0; }  void alter_age( struct person p ) {    p.age = 42; }  Prodoc (discuss • contribs) 15:10, 2 August 2011 (UTC)
 * I agree that it is confusing and should be clarified. However, the alternate example provided here would not work (and mightnot compile) because alter_age requires a struct, and cannot take a pointer to a struct.  It might be better to offer two examples - one that works, and one that does not:

Example of code that will not work as intended

Example of code that will work as intended

--Jomegat (discuss • contribs) 16:04, 2 August 2011 (UTC)
 * Good point, of course my example will not work. Hey, I'm not reading a C primer for no reason ;-) With some form of emphasis in the characters "&" and "*", in the code itself or as a separate note, the two examples would be perfect. Prodoc (discuss • contribs) 15:27, 3 August 2011 (UTC)

Missing pointer topic explanation and/or error(s)?
I just noticed two more issues which are not dealt with.
 * 1) Pointer indication before a function, like the example containing "*strtest"
 * 2) Pointer indication behind a function parameter, like the example containing "struct v*" (three times).

The first issue is valid, but what is its purpose? Why and when should you use this? If it's outside of the scope of the book, it should not be used in an example imho. The second issue looks to me to be an error. Prodoc (discuss • contribs) 15:42, 3 August 2011 (UTC)

Type
Is it my impression or int and float are machine dependent or implementation (they can be 16 or 32 bits, or 8 in case of the float, but not size guaranteed). --Panic (discuss • contribs) 07:12, 17 April 2012 (UTC)