Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » code syntax formatter no indent after __init
code syntax formatter no indent after __init [message #991815] Thu, 20 December 2012 09:01
Jonas Jensen is currently offline Jonas JensenFriend
Messages: 1
Registered: December 2012
Junior Member
I think I may have found a bug in the C-style code syntax formatter.

To prove this is not a problem with custom styles, this also happens with the built-in styles.

Here's what happens:

All functions after "__init" are formatted without indentation.

Example 1:
crc32 declared after __init. No indentation for crc32.
static void __init moxart_get_mac_address(struct net_device *dev, u8 mac_addr_flash_offset) // Get MAC address stored in flash memory and write it to net_device
{
	int i;
	for (i=0; i <= 5; i++) dev->dev_addr[i] = inb(IO_ADDRESS(MOXART_FLASH_BASE) + mac_addr_flash_offset + i);
	dbg_printk("MOXART Ethernet: finished get_mac_address dev->base_addr=%x\n", (unsigned int) dev->base_addr);
}
static int crc32(char * s, int length) {
int perByte;
int perBit;
const unsigned long poly = 0xedb88320; // crc polynomial
unsigned long crc_value = 0xffffffff; // crc value - preinitialized to all 1's

for (perByte = 0; perByte < length; perByte++) {
	unsigned char c;
	c = *(s++);
	for (perBit = 0; perBit < 8; perBit++) {
		crc_value = (crc_value >> 1) ^ (((crc_value ^ c) & 0x01) ? poly : 0);
		c >>= 1;
	}
}
return crc_value;
}



Example 2:
crc32 now declared before __init. Format indents the code correctly.
static int crc32(char * s, int length) {
	int perByte;
	int perBit;
	const unsigned long poly = 0xedb88320; // crc polynomial
	unsigned long crc_value = 0xffffffff; // crc value - preinitialized to all 1's

	for (perByte = 0; perByte < length; perByte++) {
		unsigned char c;
		c = *(s++);
		for (perBit = 0; perBit < 8; perBit++) {
			crc_value = (crc_value >> 1) ^ (((crc_value ^ c) & 0x01) ? poly : 0);
			c >>= 1;
		}
	}
	return crc_value;
}
static void __init moxart_get_mac_address(struct net_device *dev, u8 mac_addr_flash_offset) // Get MAC address stored in flash memory and write it to net_device
{
	int i;
	for (i=0; i <= 5; i++) dev->dev_addr[i] = inb(IO_ADDRESS(MOXART_FLASH_BASE) + mac_addr_flash_offset + i);
	dbg_printk("MOXART Ethernet: finished get_mac_address dev->base_addr=%x\n", (unsigned int) dev->base_addr);
}



Example 3:
crc32 declared after but this time with __init removed. Format indents the code correctly.
static void  moxart_get_mac_address(struct net_device *dev, u8 mac_addr_flash_offset) // Get MAC address stored in flash memory and write it to net_device
{
	int i;
	for (i=0; i <= 5; i++) dev->dev_addr[i] = inb(IO_ADDRESS(MOXART_FLASH_BASE) + mac_addr_flash_offset + i);
	dbg_printk("MOXART Ethernet: finished get_mac_address dev->base_addr=%x\n", (unsigned int) dev->base_addr);
}
static int crc32(char * s, int length) {
	int perByte;
	int perBit;
	const unsigned long poly = 0xedb88320; // crc polynomial
	unsigned long crc_value = 0xffffffff; // crc value - preinitialized to all 1's

	for (perByte = 0; perByte < length; perByte++) {
		unsigned char c;
		c = *(s++);
		for (perBit = 0; perBit < 8; perBit++) {
			crc_value = (crc_value >> 1) ^ (((crc_value ^ c) & 0x01) ? poly : 0);
			c >>= 1;
		}
	}
	return crc_value;
}


Any idea why this happens? Is there a workaround? "__init" is defined in the linux kernel source as:
#define __init __section(.init.text) __cold notrace
Previous Topic:Error message from debugger back end
Next Topic:Debugger won't stop at breakpoints
Goto Forum:
  


Current Time: Fri Mar 29 01:05:27 GMT 2024

Powered by FUDForum. Page generated in 0.04059 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top