Format string in files.c, line 2717

Discussion around programming R'n'D, its source code and its tools.

Moderators: Flumminator, Zomis

Post Reply
Zomis
Posts: 1502
Joined: Mon Jun 21, 2004 1:27 pm
Location: Sweden
Contact:

Format string in files.c, line 2717

Post by Zomis »

files.c, line 2717

Code: Select all

  if (!element_found)
  {
    char *error_conf_chunk_bytes =
      (byte_mask == CONF_MASK_1_BYTE ? "CONF_VALUE_8_BIT" :
       byte_mask == CONF_MASK_2_BYTE ? "CONF_VALUE_16_BIT" :
       byte_mask == CONF_MASK_4_BYTE ? "CONF_VALUE_32_BIT" :"CONF_VALUE_BYTES");
    int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN;
    int error_element = real_element;

    Error(ERR_WARN, "cannot load micro chunk '%s(%d)' value for element %d ['%s']",
	  error_conf_chunk_bytes, error_conf_chunk_token,
	  error_element, EL_NAME(error_element));
  }
I wonder if the format string "cannot load micro chunk '%s(%d)' value for element %d ['%s']" corresponds correctly with the values
error_conf_chunk_bytes, error_conf_chunk_token, error_element, EL_NAME(error_element)

error_conf_chunk_bytes is an integer (%d) and not a string (%s), isn't it?

And what's the use of "int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN;", anyway? I can't really figure that out...
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Post by Holger »

> error_conf_chunk_bytes is an integer (%d) and not a string (%s), isn't it?

No, it's indeed a string (char *)!

This piece of code ...

Code: Select all

char *error_conf_chunk_bytes = 
      (byte_mask == CONF_MASK_1_BYTE ? "CONF_VALUE_8_BIT" : 
       byte_mask == CONF_MASK_2_BYTE ? "CONF_VALUE_16_BIT" : 
       byte_mask == CONF_MASK_4_BYTE ? "CONF_VALUE_32_BIT" :"CONF_VALUE_BYTES"); 
is the same as if I would have written the following:

Code: Select all

char *error_conf_chunk_bytes;  /* this is a string pointer */
if (byte_mask == CONF_MASK_1_BYTE)
  error_conf_chunk_bytes = "CONF_VALUE_8_BIT"; /* still a string :-) */
else if (byte_mask == CONF_MASK_2_BYTE)
  error_conf_chunk_bytes = "CONF_VALUE_16_BIT";
else if (byte_mask == CONF_MASK_4_BYTE)
  error_conf_chunk_bytes = "CONF_VALUE_32_BIT";
else
  error_conf_chunk_bytes  = "CONF_VALUE_BYTES";
> And what's the use of "int error_conf_chunk_token = conf_type &
> CONF_MASK_TOKEN;", anyway? I can't really figure that out...

This is just the number of the token of that type. It directly corresponds to the values in "static struct LevelFileConfigInfo chunk_config_INFO[]" etc., where it is initialized like this:

Code: Select all

  {
    -1,                                 SAVE_CONF_ALWAYS,
    TYPE_INTEGER,                       CONF_VALUE_8_BIT(1),
    &li.game_engine_type,               GAME_ENGINE_TYPE_RND
  },
Therefore, the warning displays something like "CONF_VALUE_8_BIT(1)", and you then know what it is!
HerzAusGold
Posts: 362
Joined: Sun Sep 25, 2005 4:41 pm
Location: Germany

Post by HerzAusGold »

char *error_conf_chunk_bytes =
This is a char pointer! Filling depends on the "byte_mask".
If value of byte_mask is CONF_MASK_1_BYTE then this pointer points to
"CONF_VALUE_8_BIT" aso.

Generall rule:
a = (value == 0) ? TRUE : FALSE;
is the same as
if (value == 0) {
a = TRUE;
} else {
a = FALSE;
}
int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN;
This is a bitwise AND to find out what bits are set. The interessting bits are in CONF_MASK_TOKEN.
The variable is only for logging the result value.
And the answer is ... 42 !
Post Reply